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     := 'ourPOPHost.com'.
   popUsername := 'popUser'.
   popPassword := 'POPpassword'.
   client := NetClients.POP.POPClient connectToHost: popHost.
   [client
       username: popUsername
       password: popPassword.
       client login.
       client
           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 := 'joe.smith@example.com'.
 smtpToAddr   := 'mary.jones@example.com'.
 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

 %4
 '   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: 'addr@domain1.com' to: 'addr@domain2.com' 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