- Code: Select all
- (void)sendMessage:(EDInternetMessage *)message;
It will be useful first to study the following method in EDMailAgent, which constructs plain text messages
- Code: Select all
- (void)sendMailWithHeaders:(NSDictionary *)userHeaders body:(NSString *)body andAttachments:(NSArray *)attachmentList
Then you can do something similar for HTML messages. The EDInternetMessage object would be created from an EDHTMLTextContentCoder, roughly like this:
- Allocate an EDHTMLTextContentCoder
- Use initWithText: to pass in the HTML source
- Call the "message" method on the coder to get the message
- Add the headers to the message using addToHeaderFields:
In summary the code could look as follows:
- Code: Select all
NSString *htmltext = @"<html><body>Hello,<br>this is a HTML email test!</body></html>";
EDHTMLTextContentCoder *htmlcoder=[[[EDHTMLTextContentCoder alloc] initWithText: htmltext] autorelease];
EDInternetMessage *message=[htmlcoder message];
[message addToHeaderFields:[EDObjectPair pairWithObjects:EDMailFrom:@"sender@example.com"]];
[message addToHeaderFields:[EDObjectPair pairWithObjects:EDMailTo:@"receiver@example.com"]];
[message addToHeaderFields:[EDObjectPair pairWithObjects:EDMailSubject:@"An HTML email"]];
EDMailAgent *mailAgent = [EDMailAgent mailAgentForRelayHostWithName:@"smtp.example.com"];
[mailAgent sendMessage:message];
