I am creating an email in MFMaiilComposeViewController and if I simply create some html snippets and assign them to the message body - all is well. The resulting email (in GMail and Yahoo) looks like the original HTML I sent.
[mailMan_ setMessageBody:body isHTML:YES];
On the other hand, if I also include an XML attachment, my email reader renders everything as plain text … including, the XML inlined. IE: my mail client (GMail, Yahoo) shows the raw HTHML and XML tags - including html tags that I didn't supply - ie: the html, head, body tags the iPhone provides around the content:
NSData *opmlData = [[NSData alloc] initWithData:[opml dataUsingEncoding:NSUTF8StringEncoding]];
NSString *fileName = [NSString stringWithFormat:#"%f.opml", [NSDate timeIntervalSinceReferenceDate]];
[mailMan_ addAttachmentData:opmlData mimeType:#"text/xml" fileName:fileName];
I pop3'd the mails to see what was happening and found that WITHOUT an attachment, the resulting html section of the email contains this block:
--0-1682099714-1273329398=:59784
Content-Type: text/html; charset=us-ascii
<html><body bgcolor="#FFFFFF"><div><h2 style="b
while on the other hand, WITH the XML attachment, the iPhone is sending this:
--0-881105825-1273328091=:50337
Content-Type: text/plain; charset=us-ascii
<html><body bgcolor="#FFFFFF"><div><h2 style="bac
Notice the difference? Look at the Content-Type … text/html vs text/plain. It looks like when I include an XML attachment, the iPhone is errantly tagging the HTML version of the body as plain text! Just to clarify, technically, both with and without the attachment, the iPhone also includes this:
--0-881105825-1273328091=:50337
Content-Type: text/plain; charset=us-ascii
Notebook
Carpentry
Bathroom floor tile
Bathroom wall tile
Scrape thinset
But this obviously isn't where the problem lies.
Am I doing something wrong? What must I do to actually "attach" XML without the iPhone labeling the entire HTML body as plain text. I tried reversing the assignments (attachment first and then body) but no luck.
For what it's worth, the email looks perfect from the iPhone's sending interface. Indeed, the HTML renders correctly and the attachment looks like a little icon at the bottom of the message. This problem has more to do with what the iPhone is actually sending.
Turns out - this problem is specific to Yahoo.
On the iPhone, if I change my provider to my Gmail account instead of my Yahoo account, the resulting email has more sections, is much more specific and renders correctly.
Moral of the story - be careful sending attachments from your iPhone via different providers.
Related
I have been trying to locate all attachments on an email that has inline attachments with no content-disposition.
This is a snippet of the email
----boundary_4451_1ea18041-d01e-46e2-8f88-32770bfba1b7
Content-Type: application/octet-stream; name=img0.png
Content-Transfer-Encoding: base64
Content-ID: <image1>
..image base64 here..
----boundary_4451_1ea18041-d01e-46e2-8f88-32770bfba1b7
Have tried the Attachments collection but its obviously not in there.
Have also tried an approach where the "body" is identified and then everything else is treated as an attachment. However this picks up the html body as an attachment too because the headers for that are also suspect.
Any help appreciated or if you need more info please let me know. Thanks.
The MIME part that you've pasted the raw source for in your question will be located in MimeMessage.BodyParts because it is not tagged as an attachment via the Content-Disposition header, as you've noticed.
Every email client has its own idea of what constitutes an attachment and so it is up to you to decide how to determine if something is an attachment or not, that's not something that MimeKit can determine for you.
Have you checked out the HtmlPreviewVisitor sample code located in the FAQ?
That sample code snippet shows you how to render an email message as HTML and gather up all of the referenced image attachments, etc. and it collects all of the other non-referenced attachments into an attachment list.
I'm looking to call the Gmail app with a preconfigured subject and the body contains HTML using the following:
let gmail = URL(string:"googlegmail:///co?subject=Subject&body=<body><H1>testing</H1></body>")
UIApplication.shared.openURL(gmail!)
This will crash the app, I then resort to:
var messageEncoded1 = "<body><H1>testing</H1></body>".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
let gmail = URL(string:"googlegmail:///co?subject=Subject&body="+messageEncoded1!")
UIApplication.shared.openURL(gmail!)
And this will create a URL and open Gmail, however, body of the email shows: <body><H1>testing</H1></body> and not the work testing like so:
testing
So the question is, is there a way to specify that the body holds HTML so that Gmail can render it as HTML?
No, for now, Gmail doesn't render it as HTML. Moreover, mailto standard RFC2368 itself doesn't obligate to render tags in body property:
The special hname "body" indicates that the associated hvalue is the
body of the message. The "body" hname should contain the content for
the first text/plain body part of the message. The mailto URL is
primarily intended for generation of short text messages that are
actually the content of automatic processing (such as "subscribe"
messages for mailing lists), not general MIME bodies.
I am learning networking recently.
It is known that SMTP only allows 7-bit ASCII.
I would like to know if SMTP can send attachment such as pictures, videos or files via email. If so, how can the attachment be sent?
Thank you
With SMTP, almost every email is using MIME (Multipurpose Internet Mail Extensions, RFC2045). MIME is independent of SMTP, but can be thought like extension to it. HTTP protocol is also using MIME.
MIME contains two parts. MIME headers and MIME content. MIME headers describe what the contents will be. MIME is full of features, but I'm only describing what is relevant to your question.
MIME headers of interest:
Content-Type describe what the content is. Simply, text is just text/plain and image/jpeg is JPEG image.
Content-Transfer-Encoding describe how the content is encoded. Common encodings in email are quoted-printable and base64. These encodings are designed for SMTP's 7bit delivery in mind.
Content-Disposition header contains for example attachments file name.
For sending attachment or multiple attachments, each attachment is encoded as described above (some headers + encoded content). First Content-Type header is set to multipart/mixed and given boundary tag like this:
Content-Type: multipart/mixed; boundary=4vvtTcl0dIpecpyi12ab54
And every attachment (headers + content) starts with boundary tag:
--4vvtTcl0dIpecpyi12ab54
followed by MIME headers and then contents. This way the email client can separate attachments from each other.
I would also like to mention that there is 8BITMIME extension to SMTP for 8 bit support. See RFC6152: SMTP Service Extension for 8-bit MIME Transport.
I'm letting my App's user send email from within the app to share some content on myserver. To do so I need to include a button with two bits of data and I want to use POST to keep it somewhat hidden. I've decided to add an html form using POST and two hidden fields in the email rather, like so:
NSString *buttonCode = [NSString stringWithFormat:#"<form method='post' action='http://www.example.com/iphone/nifty.php'>
<input type='hidden' name='dataOne' value='%#'>
<input type='hidden' name='dataTwo' value='%#'>
<input type='submit'value='Submit'></form>",dataOne, dataTwo];
NSString *emailBody = [NSString stringWithFormat:
#"<b>%# - %#</b>\n\n<HR WIDTH=200 SIZE=2 COLOR=#755f0f ALIGN=CENTER>\n Here is a email:<br><br>%#",
dateString,
timeString,
buttonCode];
[picker setMessageBody:emailBody isHTML:YES];
I've confirmed by looking at the raw source of the email that the form is constructed correctly and I've copied and pasted it into a web page and it works.
So here is the problem. When I click on the button in the received email (using apple's mail client) the dataOne and dataTwo variables don't get passed to my server.
Is there a better way to do this or is the issue with my mail client?
====== update ==========
I think this may be related to the line the iPhone adds to the email:
--Apple-Mail-1--23863057
Content-Type: text/html;
charset=utf-8
Content-Transfer-Encoding: 7bit
When I add enctype="text/html" to the form in the test html on the server as mentioned above the variables are not received.
Is there a way to alter this from the iPhone and send it another way?
The enctype just tells the mail client that the email contains HTML, the problem is that your mail client is dropping the fields.
I'm trying to send a JPG attachment with a formatted HTML message. Of course I'm using [picker setMessageBody:emailBody isHTML:YES];
The rest of the code is what it is supposed to be, according to various messages on forums.
What I observe: the contents of the resulting e-mail message depends on the configured e-mail account on your iPhone.
E.g.: for a Yahoo mail account, setting isHTML to YES never results in an HTML message, but setting it to NO does! Bug in Apple stuff?
But, for a GMail account, I've never succeeded to send an HTML mail, it is always received as plain text.
The JPG file is sometimes shown inline, sometimes as an attachment.
All I want: send a JPG file, and a message containing some line breaks. Does anybody have some proven code that does just that, working for all kinds of e-mail accounts?
Even if you set isHTML param to YES, your message body can be sent as plain/text if the message body can be represented as such. And attachments in plain/text messages are not always recognized correctly by some email clients (Outlook).
In my case adding a link in the message body helped. Formatting text as bold with HTML tags works too. Tricky!
Tested on iPod 1G 3.1.3.