Question

I've been able to hack my way through scripting bridge and apple mail and can now send emails from my cocoa program. Now, I'm trying to send HTML mail and have run into a snag. In short, I have generated an NSString containing the entire HTML code from the open html tag through to the slash-html close tag with all the goodies in between.

However, when I pass that as content through scripting bridge, all I end up with is a email in which I can read the HTML code... I would say it's plain text, but links still show as clickable links, so that's not entirely true.

If I open the code in Safari, the HTML displays correctly.

I thought perhaps it may have to do with the header information in the email message, but if there is a way to set that through scripting bridge, I haven't found a way to do that yet. Again, since links are clickable, I'm thinking they may not be the problem?

If there is a way to set the header information to "Content-Type: text/html; charset=ISO-8859-1" and "MIME-Version: 1.0" and anyone knows how, please enlighten me :)

If not, does anyone have any suggestions? I'm sure that I must be missing something, and I'm hoping it's simple.

* EDIT *

I tried opening my HTML file in Safari and using the FILE>Email Contents which then creates a new email in Apple Mail. This new email is viewable as HTML. Thus, I know it must be possible to do this.

I then send that email to myself, as well as a non-html email.

Inspecting just the header information on both files revealed that the content-type is identical on both of these emails, being listed as:

multipart/alternative; boundary="Apple-Mail=_D0859731-3A0F-459E-9673-DEC0FC6503BF"

Of course, the ID string is different on each email sent...

However, when viewing the raw source, the HTML file does in fact have a second content-type which specifies "text/html" just before the HTML code (which I interpret to mean that the multipart/alternative simply instructs the mail app to look for additional content-type tags...

Was it helpful?

Solution 2

From what I can tell, Apple does not allow you to directly send an HTML email through scripting bridge. I could speculate on the reasons they frown upon this (spam, security, etc.) but it seems that it is what is is.

The workaround was to open the HTML in Safari and then use Scripting Bridge to "Email Contents of This Page" to Mail. This creates a new outgoing mail in Mail.app which contains the HTML code.

NOTE: One side effect I've noticed however, is that when using scripting bridge to add recipients to the email after it's been created by Safari, an additional DIV tag with in-line code is created for each and every recipient. Thus, as the default is to add a line break before and after each DIV tag on display, the HTML code begins further down the page for each recipient added. A workaround is to use CSS in your HTML code to override the default display behavior for DIV tags. I've explained it in more detail here:

Scripting Bridge adds unwanted HTML code when adding recipient to mail

OTHER TIPS

Here's what you need:

Open Source Cocoa/Cocoa-Touch POP3/SMTP library?

(A mail library of functions)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top