Sending HTML email with EDMessage

Discussion of the EDMessage and EDCommon frameworks.

Sending HTML email with EDMessage

Postby erik » 10 Oct 2009, 18:46

EDMailAgent has some convenience methods to send plain text. If you want to send HTML messages (or anything else, really) you will have to use the following method:

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:@""]];
    [message addToHeaderFields:[EDObjectPair pairWithObjects:EDMailTo:@""]];
    [message addToHeaderFields:[EDObjectPair pairWithObjects:EDMailSubject:@"An HTML email"]];
    EDMailAgent *mailAgent = [EDMailAgent mailAgentForRelayHostWithName:@""];
    [mailAgent sendMessage:message];
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: Sending HTML email with EDMessage

Postby tciuro » 19 Jan 2010, 05:08


While the example is very clear and informative, it leaves to speculation whether a content-rich HTML message can be sent via EDMessage. If so, how would the example look like? Ideally I would like to avoid additional downloads, so the images would have to be embedded. Something similar to this example:

Any pointers? Thanks!

-- Tito
Posts: 1
Joined: 19 Jan 2010, 05:06

Re: Sending HTML email with EDMessage

Postby erik » 19 Jan 2010, 12:03

Yes, you can send such emails with EDMessage. The trick lies in creating the right message structure and linking the image reference to another message part. In code this could look as follows:

Code: Select all
// Create html text part

NSString *html = @"<p>This is the <b>HTML</b> version.<p><img src=\"cid:image-1\">";
EDContentCoder *coder = [[[EDHTMLTextContentCoder alloc] initWithText:html] autorelease];
EDMessagePart *htmltextPart = [coder messagePart];

// Create image part

NSData *imageData = [NSData dataWithContentsOfFile:@"edmessage.jpg"];
coder = [[[EDMultimediaContentCoder alloc] initWithData:imageData filename:@"edmessage.jpg"] autorelease];
EDMessagePart *imagePart = [coder messagePart];
[imagePart addToHeaderFields:[EDObjectPair pairWithObjects:@"Content-ID":@"<image-1>"]];

// Create a related multipart from html text part and image part

NSArray *htmlPartList = [NSMutableArray arrayWithObjects:htmltextPart, imagePart, nil];
EDCompositeContentCoder *compositeCoder = [[[EDCompositeContentCoder alloc] initWithSubparts:htmlPartList] autorelease];
EDMessagePart *htmlPart = [compositeCoder messagePartWithSubtype:@"related"];

// Create plaintext part

NSString *plaintext = @"This is the plain text alternative.";
coder = [[[EDPlainTextContentCoder alloc] initWithText:plaintext] autorelease];
EDMessagePart *plaintextPart = [coder messagePart];

// Create alternative multipart from plaintext and html parts

NSArray *textPartList = [NSMutableArray arrayWithObjects:plaintextPart, htmlPart, nil];
compositeCoder = [[[EDCompositeContentCoder alloc] initWithSubparts:textPartList] autorelease];
EDInternetMessage *message = [compositeCoder messageWithSubtype:@"alternative"];

Note how the filename of the image is irrelevant. The HTML text refers to the image by its content ID, which is something we're free to make up.

By the way, the Python example referenced further up actually has the message structure wrong. The multipart/alternative should be at the top level and the multipart/related nested below it.

Lastly, I've attached a sample project that contains this code, and also shows how to deliver the message over a secure and password protected SMTP link. If you run this, please, please change the recipient address and mail server details.
Example: Message with embedded image.
(698.27 KiB) Downloaded 871 times
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Re: Sending HTML email with EDMessage

Postby Jocelyn » 21 Oct 2010, 03:22

Thank you Erik. :D

Really appreciate EDMessage and your posts to the forum.
Posts: 2
Joined: 20 Oct 2010, 01:02

Sending HTML email with EDMessage

Postby natorTuM » 03 Jun 2017, 04:36

We are seriously considering buying this EZmail script BUT judging from what we see in the demo, it appears to only take text email. We want to know if its possible to send an HTML email to those on the subscribtion list. Please advice HOW we can do it.
[url=]Производство бетона
Posts: 5
Joined: 20 May 2017, 17:11
Location: Россия

How can i spread movie site with your community??

Postby MyfilmQuime » 19 Jul 2017, 17:43

{Hi|Hello} {!!|!| }
I didnt find any related topic, so i will start here {..|...|.|, ok?}
{As i|I} see {your site|this site} #hostname have {big amount of|a lot of} {friendly users,|kindly users,|users interested in my movie site|active users,} have you {any kind of|some kind of} advertising {here|there|herein|therein|at this point|in these parts}? {Free, Paid, etc|Free or Paid|Maybe free, payed or excnahging?}
I want to buy {1-2 banners|some banners|some traffic from your site}, how can i do it? {Please look at my site|could look at my site} ( and {answer me by| the answer please send me to my} {email|mail|contacts} {with your best price|with your price|with price for my site}{?|??|???}
Users also insterested in movies and get to my site {by this queries|:
<strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>, <strong>#file_links[C:\Users\Tom\Desktop\Xrumer\temp\keywords.txt,1,L]</strong>

Please contact me by email:
{Thanks|Thank you|God bless you} in advance{!|!!|!!!|.| }
Posts: 4
Joined: 19 Jul 2017, 17:43

Sending HTML email with EDMessage

Postby SubbotaJeomo » 24 Jul 2017, 03:12

Hi Esmond,

Can you direct me to the patch please. Is it for sending reminders to clients?


Posts: 8
Joined: 12 Jun 2017, 03:58
Location: Ukraine

Return to ED Frameworks