[Seaside-dev] Extended WAEmailMessage to include headers
Udo Schneider
Udo.Schneider at homeaddress.de
Wed Nov 3 07:34:56 UTC 2010
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).
Best Regards,
Udo
More information about the seaside-dev
mailing list