Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an email header on objective-C?

I'm trying to make an app that sends an email using MFMailComposeViewController but that class doesn't seem to provide a way to set email headers.

I tried to look for a lower level solution (or even a library) that does this but couldn't find one. How can I set/get email headers in an Objective-C app?

[EDIT] To be clear, I am looking for a way to set email headers by ways other than provided by MFMailComposeViewController. I already know how to send a simple email. I am looking for a way to set email headers such as In-Reply-To, or Message-ID

like image 377
Vlad Avatar asked Sep 25 '14 05:09

Vlad


Video Answer


3 Answers

The authors of Sparrow wrote a great class called MailCore (now with version 2) that allows you to do just that.

If you'll go to the class Class documentation here: http://libmailcore.com/mailcore2/api/Classes/MCOMessageHeader.html

You can find all kind of useful headers in the properties such as messageID, inReplyTo etc'.

like image 62
Segev Avatar answered Oct 09 '22 01:10

Segev


If You want to create email header you can create your own header using html and set it as the message body of the mail with isHTML as True.

I just tried the following code:

NSString * Htmlstr =[NSString stringWithFormat:@ "<html>"
                   "<body>"
                   "<div id=\"container\" style=\"background-color:#EEEEEE;height:300px;width:500px;float:left;\">"
                   "<div id=\"header\" style=\"background-color:#FFA500;\">"
                   "<h3 style=\"margin-top:0;\">ABC</h3></div>"
                   "<div id=\"content\" style=\"background-color:#EEEEEE;height:300px;width:500px;float:left;\">%@</div>"
                   "<div id=\"Banner\" style=\"background-color:#EEEEEE;clear:both;text-align:left;margin-top:0;\"><img src=\"%@\" alt=\"Smiley face\" width=\"500\" height=\"100\"></div>"

                   "<div id=\"footer\" style=\"background-color:#FFA500;clear:both;text-align:center;margin-bottom:0;\">Copyright © abc.com</div>"
                   "</div>"
                   "</body>"
                   "</html>",emailBody,self.SelectedBannerImage];

[mailer setMessageBody:Htmlstr isHTML:YES];

Hope this helps you..

like image 32
Mahesh Avatar answered Oct 09 '22 01:10

Mahesh


I think you'd have enough resources if you used libcurl (c library) or one of its cocoa wrappers, no?

Check here for BBHTTP and CURLHandle.

That should let you manually compose your smtp traffic using cocoa/objc syntax. Is that more along the lines of what you're looking for?

like image 32
Miles Alden Avatar answered Oct 09 '22 02:10

Miles Alden