UIActivityViewController UIActivityTypeMail ruining my mail urls - html

I am trying to send an email from my app. I format the email in a custom ActivityProviderMessage along the lines of this:
return [NSString stringWithFormat:#"<html><body>This is my html email body and
here is a very long url link: Long url link</body></html>", _url];
The problem with this, is when I receive the email and take a look at the source, the url is screwed up because it has been put on multiple lines with lots of = inserted at the end of each line.
The URL is actually a Base64 encoded image, which when pasted into safari shows the image fine.
Here's an example of a small image url, paste it into safari and you'll see the image:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoxMTFGOTk4Q0NGNzIxMUUyOUY1REQxQkQ4NDFFMzEwMCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoxMTFGOTk4RENGNzIxMUUyOUY1REQxQkQ4NDFFMzEwMCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjExMUY5OThBQ0Y3MjExRTI5RjVERDFCRDg0MUUzMTAwIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjExMUY5OThCQ0Y3MjExRTI5RjVERDFCRDg0MUUzMTAwIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+R9i41AAAAedJREFUeNq8l81Kw0AQx9NQPHupoAhttVqw2oqePPkK3n0DT55sK1ZBq1a9+CIefADPnvyoVfEzVVAQwZMoFEGchQ2Mf3aTTdp04E93N7P5JbszO2kssfZjRWAOKU0aJL2qHOwIocJeSCPdAN8yqGt3pGyU4AZpVHPthjQUBficNO7j80ga6CT4ilQw9BWBlhCNeJvQJ1Iy4Jx3Up/dZvRy6FuAuWdhwU2I3gqpX/762YPI7zBgMTEF0KpsV33gDTev7RCBNMz6RQa1GLyomHtByoeJ6jppjPXLpF3DudcY+abgf09LViLVNL4rpB3I3xw6maTTPSnD+kukPQ/oBqRbRuUYN4jeFLypDroM0CYek6ZL7QAUl9CCINtk/WcvqBfYgTxdhRsjtAaBlPLbP9ugtOES4p7WIPJzJtFq+5Q2sWTbmrkleKBL0qRpbiIYS1tS5itaGR5IFPuJICcRBy9ofLbgGKzIMR692aDnbhwCyLUp0gHb63XSL2sbpYyXxeRXZg+pxcc1eYy1OB22ptqKvZ1nbXHjY02FCg3lS32iKOizshLNKCI/3+73kgD3wpiIziOPYlGwOmBiqb9hbF/h90Fa7BTUfeOWx/U50mEU/3FU1WmadGpFbAL8KY9J8ftldcn+BBgAl0Jc3zM1awwAAAAASUVORK5CYII=
Now when I log the message returned from my ActivityProviderMessage method it looks like this, which works as it should (Paste into a .html and open it, the link shows the image):
<html><body>This is my html email body and here is a very long url link: <a href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoxMTFGOTk4Q0NGNzIxMUUyOUY1REQxQkQ4NDFFMzEwMCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoxMTFGOTk4RENGNzIxMUUyOUY1REQxQkQ4NDFFMzEwMCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjExMUY5OThBQ0Y3MjExRTI5RjVERDFCRDg0MUUzMTAwIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjExMUY5OThCQ0Y3MjExRTI5RjVERDFCRDg0MUUzMTAwIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+R9i41AAAAedJREFUeNq8l81Kw0AQx9NQPHupoAhttVqw2oqePPkK3n0DT55sK1ZBq1a9+CIefADPnvyoVfEzVVAQwZMoFEGchQ2Mf3aTTdp04E93N7P5JbszO2kssfZjRWAOKU0aJL2qHOwIocJeSCPdAN8yqGt3pGyU4AZpVHPthjQUBficNO7j80ga6CT4ilQw9BWBlhCNeJvQJ1Iy4Jx3Up/dZvRy6FuAuWdhwU2I3gqpX/762YPI7zBgMTEF0KpsV33gDTev7RCBNMz6RQa1GLyomHtByoeJ6jppjPXLpF3DudcY+abgf09LViLVNL4rpB3I3xw6maTTPSnD+kukPQ/oBqRbRuUYN4jeFLypDroM0CYek6ZL7QAUl9CCINtk/WcvqBfYgTxdhRsjtAaBlPLbP9ugtOES4p7WIPJzJtFq+5Q2sWTbmrkleKBL0qRpbiIYS1tS5itaGR5IFPuJICcRBy9ofLbgGKzIMR692aDnbhwCyLUp0gHb63XSL2sbpYyXxeRXZg+pxcc1eYy1OB22ptqKvZ1nbXHjY02FCg3lS32iKOizshLNKCI/3+73kgD3wpiIziOPYlGwOmBiqb9hbF/h90Fa7BTUfeOWx/U50mEU/3FU1WmadGpFbAL8KY9J8ftldcn+BBgAl0Jc3zM1awwAAAAASUVORK5CYII='>Long url link</a></body></html>
However the received email source in mail.app looks like this:
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D= utf-8"></head><body dir=3D"auto"><div>This is my html email body and here is= a very long url link: Long url link</div><div><br><br>Sent from my iPh= one</div></body></html>=
I notice that the received email automatically has a new Head tag in it, even if I supply my own in the email:
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D= utf-8"></head>
So, to get this working, is it simply a case of finding a right format for the url?
Or perhaps I need extra fields when I generate the email to tell mail.app not to change anything?
Please help.
Thanks

If you are trying to send an email with an attachment, then use this method:
- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename
Otherwise, if your goal is to show an embedded image inline in the message, then you should use a standard <img> tag in the body of your email with a url that points to an image already publicly available online.

Related

Want to create a link I can send people that will open their email app with a pre-written message (NOT A LINK ON MY OWN WEBPAGE OR APP)

I am trying to replicate something someone has done in this link https://l.instagram.com/?u=http%3A%2F%2Ftinyurl.com%2Fyd49a4ow&e=ATMn3WfYRw5VZzFDz9FU9Pp0jqk5uBpX0Vo4n2MffH-mr8W5f84IEmpo-Rbx3neyIU0ehQcntNJuRsSGfW9bjw&s=1.
When on a mobile app the link opens the mail app with a pre-written email body subject and recipients.
It is similar to the mailto function if I were designing my own web page and using HTML but this is a link I want to be able to email and share with people.
Thanks so much for your help!
Checkout mailto links: https://css-tricks.com/snippets/html/mailto-links/
The long-and-short of it is that you can make a link that looks like this:
Email Us
Basically, you are using the link's query parameters to preset the subject line, recipient, and body of the email.
Build your link like so:
mailto:<the *recipient's* email>?subject=<subject line>&body=<email content>
Then you can add the following options:
Carbon Copy (cc) and Blind Carbon Copy (bcc)
Each email must be separated by a comma (&cc=email#example.com, email2#example.com)
Subject (subject)
Email body text (body)
Make sure to URL-encode the subject and email body text as well.

Submit to HttpHandler results in RequestType GET instead of POST

My ActionHandler.ashx file should be POSTed yet upon entry to ProcessRequest the context.Request.RequestType is always "GET".
Background:
This HttpHandler currently works OK (i.e. clicking a link in an email causes my ActionHandler.ashx to be entered and the querystring is processed correctly). For example:
https://mdwdata/CorporateBrain/ActionHandler.ashx?Action=MarkComplete&ID=1024~nzmewoojgnn&CUID=13
is the URL for the link shown as Mark-Complete in the image just below:
But now I am trying to improve it by following this advice in a previous SO thread :
"In the body of the email, instead of sending a link, include an HTML form that contains a button which performs a postback to your server."
Problem Summary: When I click the Submit button, my handler is entered with verb GET not POST (hence, I have no access to the hidden form data in the Request.Form collection.
Here is a snippet (image) of the email body
If I can get the Submit to post the hidden form variables to my handler, then of course I would remove the links. In the debugger, I verified the form data and it looks good me:
I added this line to my web.config file:
<add path="ActionHandler.ashx" verb="GET,POST" type="System.Web.UI.SimpleHandlerFactory" validate="true" />
Also, my email client is Thunderbird.
What would cause the request to be GET instead of POST?
The short answer to this problem is that Thunderbird does not POST to the URL in the Action attribute of the HTML form tag. Even the newest version of Thunderbird (version 31.2.0) "ignores" the POST and requests the URL via GET.
The construction of the HTML form is properly done and other email clients I have tested work fine:
Microsoft Office 365 Outlook Web App
Google GMail
So, I guess I am doing it "right" but some email clients apparently don't support this (even my favorite which is Thunderbird).

How to pass request URL to mailto body

I need to pass URL to the body part of the mailto link.
Sample URL :
www.test.com?param1=value1&param2={value2}
If i pass this URL, it's cut down after the '&'. So, i have tried to encode the URL like below:
www.test.com%3Fparam1%3Dvalue1%26param2%3D%7Bvalue2%7D
It works, but the URL is not readable. How can we achieve this without encoding or showing readable URL in the mail body?
Try this bit of code:
Send Mail' with current webpage (offline mode will send file location on disk).
When is doubt, read the specification:
http://shadow2531.com/opera/testcases/mailto/modern_mailto_uri_scheme.html
Validator available at the bottom of the page.

Attachment + Email + HTML + Play Framework

I'm using play framework in this project and I'm trying to send an E-mail with a Logo attached but I want to show this logo as part of my HTML code!
My Mailer:
EmailAttachment attachment = new EmailAttachment();
attachment.setDescription("Logo");
attachment.setName("logoMail.jpg");
attachment.setPath(Play.getFile("/public/images/email/logoMail.jpg").getPath());
addAttachment(attachment);
My HTML
The e-mail is sent, my Logo is attached there, but the image is never showed as a background on my DIV.
What am I doing wrong?
Thank you very much!
It depends on the e-mail client you are using to read your test e-mail. Most of them ignore or remove the background-image css property.
Take a look at the following:
http://www.email-standards.org/
http://www.campaignmonitor.com/design-guidelines/
I've been looking into embedding images into emails using MVC templates, and I think at the moment it's not supported.
As far as I can see, in order to use embedded images, the image attachment needs to have a Content-ID header on it. Attaching the image using addAttachment generates an attachment without this header.
The underlying email framework, apache commons email, allows you to embed images using the HtmlEmail.embed method, and there is an example of this in the Play documentation, but only when using Commons Email directly. addAttachment() will add an ordinary attachment, not an embedded one.
The problem is that HtmlEmail.embed returns the content id for the embedded image. The first problem is that there would need to be a mechanism for passing that content id forward into the template, so that you could reference it in the relevant link.
The second problem is that the way the Mailer.send() method is coded, the email itself is not created until after the template is rendered, and the result of attempting to render an html body is used to decide whether to create an HtmlEmail or a SimpleEmail. This method would need to be re-written to decide the type of email before rendering the template, and, if it was html, to create the HtmlEmail and attach the embedded images prior to rendering the template, so that it could pass the content ids to the renderer.
It certainly isn't impossible to make this change, and I might attempt it if I can find the time on my current project.
The solution could be to render HTML content manually and then put it into email. This code worked for me:
public static String test() throws EmailException, MalformedURLException {
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.server.com");
email.setAuthentication("username", "pwd");
email.setSubject("subject");
email.addTo("to#example.com");
email.setFrom("from#example.com");
URL url = new URL("https://example.com/image.png");
String cid = email.embed(url, "IMG1");
Template templateHtml = TemplateLoader.load("/Mails/test.html");
final Map<String, Object> templateHtmlBinding = new HashMap<String, Object>();
templateHtmlBinding.put("cid", cid);
String body = templateHtml.render(templateHtmlBinding);
email.setHtmlMsg(body);
return email.send();
}
I'm a bit late with my answer, but it is possible and integrates nicely with the MVC-Email tutorial. Assuming your mailer class is also notifiers.Mails, use this as a html template:
%{
String logoSrc = notifiers.Mails.getEmbedddedSrc("public/images/logo.png", "cool logo");
}%
<html>
<head>
</head>
<body>
Look at this cool image! <br>
<img src="${logoSrc}">
<br>
Amazing, no?
</body>
</html>

How to display image in html email message?

I'm writing a j2ee application, that generates an html and sends it as email. In my html, a have an image, but it is not displayed when email is received. The html code is something like:
<img src="myimage.gif"></img>
where "myimage.gif" is sent as attached file in the email.
I tried to change it to
<img src="cid:myimage.gif"></img>
but still no result. Any ideas?
It should be without a link to the image.
You should upload your image to you server and reference that as a hard coded url in the src
e.g. upload to myserver.com/images/myimage.gif the in your html
<img src="http://myserver.com/images/myimage.gif" />
Take a look at Commons Email. It's build on top of the Java Mail API but simplifies it.
They have an example for sending html mails with inline images http://commons.apache.org/email/userguide.html
import org.apache.commons.mail.HtmlEmail;
...
// Create the email message
HtmlEmail email = new HtmlEmail();
email.setHostName("mail.myserver.com");
email.addTo("jdoe#somewhere.org", "John Doe");
email.setFrom("me#apache.org", "Me");
email.setSubject("Test email with inline image");
// embed the image and get the content id
URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
String cid = email.embed(url, "Apache logo");
// set the html message
email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");
// set the alternative message
email.setTextMsg("Your email client does not support HTML messages");
// send the email
email.send();
If the image is small enough, you could use my HTML Table pixel format :)
see my blog for details: HTML Table Pixel Format
This is just plain valid HTML, however it renders as an image.
/end of shameless plug