[Seaside-dev] Extended WAEmailMessage to include headers

Philippe Marschall philippe.marschall at gmail.com
Sat Nov 6 18:09:41 UTC 2010


2010/11/3 Udo Schneider <Udo.Schneider at homeaddress.de>:
> All,
>
> I just went through the process of sending UTF-8 encoded mail from Seaside 3.0. Doing that I discovered that you can set Mail Headers for WAEMailMessage inctances but that those headers are not passed to the underlying Platform (at least on Pharo). I extended #plainMessage to include those headers and violà .. it works:
>
> WAEmailMessageplainMessage
>        ^ String streamContents:
>                [ :stream |
>                self headers keysAndValuesDo:
>                        [ :key :value |
>                        stream
>                                nextPutAll: key greaseString;
>                                nextPutAll: ': ';
>                                nextPutAll: value greaseString;
>                                nextPut: Character cr ].
>                self
>                        renderAddress: self from
>                        withHeader: 'From: '
>                        on: stream.
>                self to do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'To: '
>                                on: stream ].
>                self cc do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'Cc: '
>                                on: stream ].
>                self bcc do:
>                        [ :each |
>                        self
>                                renderAddress: each
>                                withHeader: 'Bcc: '
>                                on: stream ].
>                stream
>                        nextPutAll: 'Subject: ';
>                        nextPutAll: self subject;
>                        nextPut: Character cr;
>                        nextPut: Character cr.
>                self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]
>
> I can now send UTF-8 encoded mails using:
>
> (WAEmailMessage from: self mailFrom toAll: self mailRecipients subject: self mailSubject)
>        addBcc: self mailBccRecipient;
>        headerAt: 'MIME-Version' put: '1.0';
>        headerAt: 'Content-type' put: 'text/plain; charset=UTF-8';
>        body: ((GRCodec forEncoding: 'utf-8') encode: self mailBody);
>        send.
>
> Is this a valid approach or did I screw up entirly (still a bad feeling modyfing "base" classes).

The headers should get passed, see WAEmailMessageTest >> #testHeaders.
The #plainMessage im my image does this except at the end instead of
the start. I'm a bit confused, how did your #plainMessage look before?

plainMessage
	^ String streamContents: [ :stream |
		self
			renderAddress: self from
			withHeader: 'From: '
			on: stream.
		self to do: [ :each |
			self
				renderAddress: each
				withHeader: 'To: '
				on: stream ].
		self cc do: [ :each |
			self
				renderAddress: each
				withHeader: 'Cc: '
				on: stream ].
		self bcc do: [ :each |
			self
				renderAddress: each
				withHeader: 'Bcc: '
				on: stream ].
		stream
			nextPutAll: 'Subject: ';
			nextPutAll: self subject;
			nextPut: Character cr.
			
		self headers keysAndValuesDo: [ :key :value |
			stream
				nextPutAll: key greaseString; nextPut: $:; nextPut: Character space;
				nextPutAll: value greaseString; nextPut: Character cr].
		
		stream nextPut: Character cr. "let body start"
		
		self body isNil ifFalse: [ stream nextPutAll: self body greaseString ] ]

Cheers
Philippe


More information about the seaside-dev mailing list