Get Content ID from MFMailComposeViewController - ios

I was searching how to add image to message body and found a lot of questions that it's impossible do it using MIME and add image to message body using standart MFMailComposeViewController.
Here: https://stackoverflow.com/a/1527833/456471
But I know the app in appstore: http://itunes.apple.com/app/emoji-free/id444304133
This app using standart mail client:
X-Mailer: iPhone Mail (9B206)
and MIME:
--Apple-Mail-FEB04051-AF80-474D-BC69-1A83514A008C
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
   charset=utf-8
<html><head></head><body bgcolor="#FFFFFF"><div></div><div><br>Brought to you by the Emoji app</div><div><br><br><img src="cid:5A2B705A-7ACB-438B-996F-FAEA8E92B28B" id="5A2B705A-7ACB-438B-996F-FAEA8E92B28B"></div><div><br><br>Best regards<div>Danil</div></div></body></html>
--Apple-Mail-FEB04051-AF80-474D-BC69-1A83514A008C
Content-Disposition: inline;
   filename=emoji.png
Content-Id: <5A2B705A-7ACB-438B-996F-FAEA8E92B28B>
Content-Type: image/png;
   name=emoji.png
Content-Transfer-Encoding: base64
Any suggestion how it can be?

Related

Multipart email with ical attachment displays incorrectly

I'm not sure if this is an issue with my code, ActionMailer, Mail, or maybe even the icalendar gem?
A user registers for an event and they get an email with an ical attachment:
# app/mailers/registration_mailer.rb
class RegistrationMailer < ApplicationMailer
helper MailerHelper
def created(registration)
...
cal = Icalendar::Calendar.new
cal.event do |e|
e.dtstart = #event.start_time
e.dtend = #event.end_time
e.organizer = 'mailto:filterbuilds#20liters.org'
e.attendee = #recipient
e.location = #location.addr_one_liner
e.summary = #summary
e.description = #description
end
cal.append_custom_property('METHOD', 'REQUEST')
mail.attachments[#attachment_title] = { mime_type: 'text/calendar', content: cal.to_ical }
mail(to: #recipient.email, subject: "[20 Liters] You registered for a filter build on #{#event.mailer_time}")
end
...
end
I have text and HTML views:
app/views/registration_mailer/created.text.erb
app/views/registration_mailer/created.html.erb
When I omit the attachment, the email is structured like this:
Header stuff...
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="--==_mimepart_63358693571_1146901122e"; charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_63358693571_1146901122e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
[the text version of the email here]
----==_mimepart_63358693571_1146901122e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
[the HTML version of the email here]
----==_mimepart_63358693571_1146901122e--
When the attachment is present, the email is structured like this:
Header stuff...
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="--==_mimepart_6335c3388b140_114924286ed"; charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_6335c3388b140_114924286ed
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
[the text version of the email here]
----==_mimepart_6335c3388b140_114924286ed
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
[the HTML version of the email here]
----==_mimepart_6335c3388b140_114924286ed
Content-Type: multipart/alternative; boundary="--==_mimepart_6335c3389bc30_114924287a3"; charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_6335c3389bc30_114924287a3
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
[the text version of the email AGAIN]
----==_mimepart_6335c3389bc30_114924287a3
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
[the HTML version of the email AGAIN]
----==_mimepart_6335c3389bc30_114924287a3--
----==_mimepart_6335c3388b140_114924286ed
Content-Type: text/calendar; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=20Liters_filterbuild_20221011T0900.ical
Content-ID: <6335c3389e99c_1149242894f#railway.mail>
[numbers and letters]
----==_mimepart_6335c3388b140_114924286ed--
It's a weird tree suddenly:
1. Content-Type: multipart/mixed
A. Content-Type: text/plain
B. Content-Type: text/html
C. Content-Type: multipart/alternative
i. Content-Type: text/plain
ii. Content-Type: text/html
D. Content-Type: text/calendar
Rails' mailer preview doesn't reproduce this issue, nor does using Litmus' email client previews (because it seems to remove the text part and attachments), but I'm assuming with the deformed structure of content-types this isn't just a client-specific rendering issue.
I'm thinking this is coming from the Mail gem underneath ActionMailer structuring the content-types oddly, but I'm a bit out of my depth here. It could be ActionMailer, I really don't know how to tell.
I'm not very well versed in this, but I think I want this structure:
1. Content-Type: multipart/mixed
A. Content-Type: multipart/alternative
i. Content-Type: text/plain
ii. Content-Type: text/html
B. Content-Type: text/calendar
So, two questions:
1. If it's my code, what am I doing wrong?
2. If it's not my code, can I force the structure I want?
I've been combing through ActionMailer and Mail code bases, but haven't found a way to manually form my email to this level.
After more digging, I'm blaming ActionMailer, though I'm still not sure why text and html parts are getting added twice.
A monkey patch for my specific use was to let ActionMailer and Mail build the mail object and then just manually remove the unwanted parts:
# app/mailers/registration_mailer.rb
...
mail.attachments[#attachment_title] = { mime_type: 'text/calendar', content: cal.to_ical }
mail(to: #recipient.email, subject: "[20 Liters] You registered for a filter build on #{#event.mailer_time}")
# PATCH: text and html parts are getting inserted in multipart/mixed (top level) as well as multipart/alternative (2nd level)
mail.parts.reject! { |part| !part.attachment? && !part.multipart? }
This only works for my specific case. If the nesting that mail creates for you is different, your reject! statement will need to be different.
In my case, mail builds this structure:
1. Content-Type: multipart/mixed
A. Content-Type: text/plain
B. Content-Type: text/html
C. Content-Type: multipart/alternative
i. Content-Type: text/plain
ii. Content-Type: text/html
D. Content-Type: text/calendar
So I step into the first level (A. - D.) and reject any parts that are not multipart and not an attachment:
1. Content-Type: multipart/mixed
A. Content-Type: text/plain <-- not multipart, not attachment = rejected
B. Content-Type: text/html <-- not multipart, not attachment = rejected
C. Content-Type: multipart/alternative <-- is multipart, not attachment = kept
i. Content-Type: text/plain
ii. Content-Type: text/html
D. Content-Type: text/calendar <-- not multipart, is attachment = kept
If you are facing this issue, I recommend you use a debugger to inspect your mail object, specifically focusing on the parts. Keep in mind that parts can be deeply nested.
Mail::Part inherits from Mail::Message which has some helpful methods you can use to determine the "shape" of your message:
multipart?
attachment?
attachments
has_attachments?
boundary
parts
all_parts
And good luck.

multipart/mixed MIME creation for amazon SES on iOS

Im constructing a MIME essentially from scratch to send emails with attachments using Amazon's SES SDK for iOS. By producing the following MIME and encoding it into a NSData object I am able to receive an email with an attached email:
From: me <from#example.com>
To: to#example.com
Subject: "example subject"
MIME-Version: 1.0
Content-Type: image/png
Content-Disposition: attachment; filename="img.png"
Content-Transfer-Encoding: base64
[giant string of base64 encoded png file omitted for brevity]
However I want to also have a plain text message in the body of the email, but I haven't been able to get my multipart/mixed message with the following format to be parsed correctly. It sends as an email with a "noname" attachment containing all the text after the first boundary.
From: me <from#example.com>
To: to#example.com
Subject: "example subject"
MIME-Version: 1.0
Content-Type: multitype/mixed; boundary="boundary--boundary--boundary"
--boundary--boundary--boundary
Content-Type: text/plain
example plain text
--boundary--boundary--boundary
Content-Type: image/png
Content-Disposition: attachment; filename="img.png"
Content-Transfer-Encoding: base64
[giant string of base64 encoded png file omitted for brevity]
--boundary--boundary--boundary--
Does anyone see something wrong with how I'm formatting the second MIME?
Thanks for your help.
You're using the wrong Content-Type. The correct MIME type for a message with this structure is multipart/mixed, not multitype/mixed.

Activesync: Sendmail command with MIME Type

<?xml version="1.0" encoding="utf-8"?>
<SendMail xmlns="ComposeMail:" xmlns:airsync="AirSync">
<ClientId>34234243</ClientId>
<SaveInSentItems />
<Mime>
From:xxx#.com
To:yyy#.com
Subject:342234 MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: base64
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 234234
This is body
</Mime>
</SendMail>
I am working with SendEmail command. I am looking for way to send Mime content to server. I have tried:
Convert the above xml in wbxml and setBOdy HTTP request but server return 103 error code.
Convert the Content betweent to Base64, and append to old string like this:
<?xml version="1.0" encoding="utf-8"?>
<SendMail xmlns="ComposeMail:" xmlns:airsync="AirSync"><ClientId>34234243</ClientId>
<SaveInSentItems/>
<Mime>
text encode base 64
</Mime>
</SendMail>
And convert to wbxml, send to server and receive error code 119 mean :MessageHasNoRecipient
The message being sent contains no recipient.
Anybody help? thanks in advance
I am sure you have a blank character before the "To" keyword in your code.
Let's remove it. Your data before you encode it to base64 encoding must to look like this:
From: xxx#xxx.com
To: xxx#xxx.com
Subject: Mail Subject
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
Test body
Best regards,
From MS documentation Mime element must be opaque BLOB https://msdn.microsoft.com/en-us/library/gg663453(v=exchg.80).aspx.
So you must write Mime data as CDATA.
<Mime>
<![CDATA[From: xxx#xxx.com
To: xxx#xxx.com
Subject: Mail Subject
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Test body]]>
</Mime>

English Email Displays Chinese-like Characters

I'm using Postal to send emails with an HTML and Text portion.
When the email is sent to Gmail, it is displayed correctly. However, when it is displayed in at least two other email systems (Mail Enable's webmail interface, and an unknown system at a client), the text is rendered as something similar to Chinese. When the client forwards the email back to a Gmail account, the "Chinese" rendering is also visible.
Example email generated:
X-Sender: no-reply#thecompany.com
X-Receiver: therecipient#thecompany.com
MIME-Version: 1.0
From: no-reply#thecompany.com
To: therecipient#thecompany.com
Date: 17 Apr 2013 22:11:25 -0700
Subject: Some Subject
Content-Type: multipart/alternative;
boundary=--boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141
----boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141
Content-Type: text/plain; charset=utf-16
Content-Transfer-Encoding: base64
MIME ENCODED CONTENTS HERE==
----boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141
Content-Type: text/html; charset=utf-16
Content-Transfer-Encoding: base64
MIME ENCODED CONTENTS HERE=
----boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141--
Clearly there is an encoding issue that Gmail somehow sorts out but other email servers do not, but what exactly is the issue?
The charset is specified as utf-16. Is does Postal (or the MVC engine) in fact generate utf-8 output? How can I control the encoding of the output and/or the charset specified in the email header?
The character encoding can be explicitly set to utf-8 by adding the headers
Content-Type: text/plain; charset=utf-8
and
Content-Type: text/html; charset=utf-8
See this article for more information.
NOTE: There is a typo in the article. The text/plain line is missing a semicolon. That is corrected in the example above.

pdf attachment not working rails3

In rails 3 when we attach pdf document in email through action mailer,
that pdf is not come as a attachment in e-mail, its come in body like
Date: Wed, 29 Dec 2010 19:56:12 +0530
Mime-Version: 1.0
Content-Type: application/pdf;
charset=UTF-8;
filename=free_book.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=free_book.pdf
Content-ID: <4d1b450431abc_### #BHUSHANF.mail>
JVBERi0xLjMKJf////8KMSAwIG9iago8PCAvQ3JlYXRvciAoUHJhd24pCi9Q
cm9kdWNlciAoUHJhd24pCj4+CmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9Q
YWdlcwovQ291bnQgMQovS2lkcyBbNSAwIFJdCj4+CmVuZG9iagozIDAgb2Jq
Cjw8IC9UeXBlIC9DYXRhbG9nCi9QYWdlcyAyIDAgUgo+PgplbmRvYmoKNCAw
IG9iago8PCAvTGVuZ3RoIDU4OAo+PgpzdHJlYW0KL0RldmljZVJHQiBjcwow
LjAwMCAwLjAwMCAwLjAwMCBzY24KL0RldmljZVJHQiBDUwowLjAwMCAwLjAw
MCAwLjAwMCBTQ04KcQoKQlQKNDEgNzQzLjUwNCBUZAovRjEuMCA4IFRmCls8
NGY3MjY0NjU3Mj5dIFRKCkVUCgoKQlQKNDEgNzM0LjI1NiBUZAovRjEuMCA4
IFRmCls8NTM3NTZkNmQ2MTcyPiAtMzAgPDc5Pl0gVEoKRVQKCjAuMDAwIDAu
MDAwIDAuMDAwIHNjbgoKQlQKMTA4IDc0My41MDQgVGQKL0YxLjAgOCBUZgpb
PDQyNjE3NDYzNjgyMDQ0NjE3NDY1MmY1NDY5NmQ2NTNhNTc+IDMwIDw2NTY0
MjA0NDY1NjMyMDMyMzkyMDMxMzkzYTM1MzYzYTMxMzEyMDJiMzAzNTMzMzAy
MDMyMzAzMTMwPl0gVEoKRVQKCjAuMDAwIDAuMDAwIDAuMDAwIHNjbgoKQlQK
MzAyIDc0My41MDQgVGQKL0YxLjAgOCBUZgpbPDRmNzI2NDY1NzIyMDYyNjE3
NDYzNjgyMDZlNmYzYTMxMzgzMjMxMzEzNTM5Mzk+XSBUSgpFVAoKMC4wMDAg
MC4wMDAgMC4wMDAgc2NuCgpCVAoyNDIuMTQ4IDY5OC44ODggVGQKL0YxLjAg
MTIgVGYKWzw1MDcyNmY2NDc1NjM3NDIwNmM2OTczNzQyMDY5NzMyMDZlNmY3
NDIwNjY+IDMwIDw2Zjc1NmU2NDJlPl0gVEoKRVQKClEKCmVuZHN0cmVhbQpl
bmRvYmoKNSAwIG9iago8PCAvVHlwZSAvUGFnZQovUGFyZW50IDIgMCBSCi9S
ZXNvdXJjZXMgPDwgL1Byb2NTZXQgWy9QREYgL1RleHQgL0ltYWdlQiAvSW1h
Z2VDIC9JbWFnZUldCi9Gb250IDw8IC9GMS4wIDYgMCBSCj4+Cj4+Ci9NZWRp
YUJveCBbMCAwIDYxMi4wIDc5Mi4wXQovQ29udGVudHMgNCAwIFIKPj4KZW5k
b2JqCjYgMCBvYmoKPDwgL0VuY29kaW5nIC9XaW5BbnNpRW5jb2RpbmcKL1R5
cGUgL0ZvbnQKL0Jhc2VGb250IC9IZWx2ZXRpY2EKL1N1YnR5cGUgL1R5cGUx
Cj4+CmVuZG9iagp4cmVmCjAgNwowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAw
MDAwMTUgMDAwMDAgbiAKMDAwMDAwMDA3MSAwMDAwMCBuIAowMDAwMDAwMTI4
IDAwMDAwIG4gCjAwMDAwMDAxNzcgMDAwMDAgbiAKMDAwMDAwMDgxNiAwMDAw
MCBuIAowMDAwMDAwOTk0IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1Jvb3QgMyAw
IFIKL0luZm8gMSAwIFIKL1NpemUgNwo+PgpzdGFydHhyZWYKMTA5MQolJUVP
Rgo=
You probably did not define a view for the action. I had the same problem as you and by creating a view in app/views/test_mailer/view.text.erb the need for a :body was rendered obsolete.
This can happen when the :body tag is not present in the mail function.

Resources