Mail scripting

I recommend you browse the NetClients package to see methods to show POP mail attributes, e.g. sender, destination, content.

POP mail snippet

   PackageLoader fileInPackage: 'NetClients'.
   popHost     := ''.
   popUsername := 'popUser'.
   popPassword := 'POPpassword'.
   client := NetClients.POP.POPClient connectToHost: popHost.
       username: popUsername
       password: popPassword.
       client login.
           getNewMailMessages: [:mimeEntity |
           | subject from |
          from := mimeEntity from printString.
          subject := mimeEntity subject printString.
          ] ]
             delete: false. "don't delete from the server"
   ] ensure: [client close].

SMTP mail snippet

 PackageLoader fileInPackage: 'NetClients'.

 smtpHost     := 'ourSMTPHost'.
 smtpFromAddr := ''.
 smtpToAddr   := ''.
 subject      := 'testing'.
 "format mailmsg exactly as shown below: left aligned on margin, 
 blank line after subject, and quote on line following message content"
mailmsg := 
'From: %1
To: %2
Subject: %3

Message content goes here.
'   bindWith: smtpFromAddr
    with: smtpToAddr
    with: subject.
  message := NetClients.MIME.MimeEntity readFrom: mailmsg readStream.
  client := NetClients.SMTP.SMTPClient connectToHost: smtpHost.
  [client sendMessage: message]
        ensure: [client close].! 

And an example script with a class around the SMTP snippet, and an error handler

 #!/usr/local/bin/gst  -f

 PackageLoader fileInPackage: 'NetClients'.

 Object subclass: SMTPHelper [

   SmtpHost := nil.

   sendEmailMsg: msg from: fromAddr to: toAddr subject: aSubject [
     | client mailmsg message |
     "Note: ensure mailmsg text is left aligned on margin"
     mailmsg :=
 'From: %1
 To: %2
 Subject: %3

 '   bindWith: fromAddr
     with: toAddr
     with: aSubject
     with: msg.

     message := NetClients.MIME.MimeEntity readFrom: mailmsg readStream.
     [client := NetClients.SMTP.SMTPClient connectToHost: SMTPHelper smtpHost.
       [ client sendMessage: message.
         Transcript showCr: 'sent mail' ]
       ensure: [client close] ]
     on: Error
     do: [ :sig | Transcript showCr: 'Error: SMTPHelper sendEmailMsg; Couldn''t connect to SMTP server. '].

     SMTPHelper class >> smtpHost [ ^SmtpHost  ]

     SMTPHelper class >> smtpHost: anSmtpHost [ SmtpHost := anSmtpHost ]
     SMTPHelper class >> test [
         SMTPHelper smtpHost: 'smtpServername.domain'.
         smtpHelper := SMTPHelper new.
         smtpHelper sendEmailMsg: 'test msg' from: '' to: '' subject: 'Testing GST smtpHelper'.
 SMTPHelper test

... you want to change your script to have delete: false. I know it's an example but...

Good point. Done.

User login