Search code examples
smalltalkpharo

Streaming over a text


I am trying to stream over text and get values that can be assigned to sender and recipient to send mail with SMTPClient

 |message sender recipient Stream peek|
  message:= 'To: [email protected], [email protected] 
             From: [email protected] , [email protected] 
             Subject: mail test

             Simple mail from me.'.

  Stream:= message readStream.
  peek:= Stream next.
  peek = $T ifTrue[Stream position 2.
                   peek:= Stream next.
                   peek = $: ifTrue["How can  get everything For To: and From:
                                      as Senders and recipients"]].

My other Question is

  SMTPClient 
  deliverMailFrom: sender
   to: recipient   
   text: message 
   usingServer: 'mail.mydomain'. 
  " ifTrue[Transcript show:('mail sent successfully')]"

How can i check this and see if mail was successfully sent


Solution

  • Please separate your questions so we can answer properly. An answer to your first question:

    | message sender recipient stream subject |
    message:= 'To: [email protected], [email protected] 
               From: [email protected] , [email protected] 
               Subject: mail test
    
               Simple mail from me.'.
    
    stream := message readStream.
    [stream atEnd] whileFalse: [
        line := stream nextLine trimBoth.
    
        (line beginsWith: 'To:') ifTrue: [recipient := line allButFirst: 'To: ' size].
        (line beginsWith: 'From:') ifTrue: [sender := line allButFirst: 'From: ' size].
        (line beginsWith: 'Subject:') ifTrue: [subject := line allButFirst: 'Subject: ' size]].
    

    I think you should have a look at the PharoByExample book. You can download it for free on the official website: http://pharobyexample.org/