Setting an email header on objective-C?
Asked Answered
S

3

6

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

Shooin answered 25/9, 2014 at 5:1 Comment(9)
Header means u wants set Subject ?Audio
there are all the methods that you need: setSubject(:) setToRecipients(:) setCcRecipients(:) setBccRecipients(:) setMessageBody(:isHTML:) addAttachmentData(:mimeType:fileName:Amazement
No, by header I actually mean the full email header en.wikipedia.org/wiki/Email#Header_fields More specifically I was trying to access headers like Message-ID or In-Reply-To.Shooin
I already know how to send simple emails using all the methods Abid mentioned above.Shooin
Have you seen mailcore? github.com/MailCore/MailCoreOsteoplastic
@NikitaTook I think you missed it but I specifically stated above I am not looking for a solution like MailCore.Shooin
@Shooin You won't find anything that integrates with built-in iOS mail that allows the setting of extra headers (mailto: supports the limited set that MFMailComposeViewController supports).Impale
Take a look at skpsmtpmessageGripper
@Shooin did you ever find a solution to this? I too would like to be able to add custom headers to an email composed using something like MFMailComposeViewController.Dorcas
L
1

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'.

Leatherman answered 29/9, 2014 at 21:51 Comment(1)
Thanks but if you read the requirement above, I specifically stated I am not looking for a solution like MailCore.Shooin
A
1

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..

Aleras answered 30/9, 2014 at 11:7 Comment(1)
Thanks, but I think there was misunderstanding. By header I meant this: en.wikipedia.org/wiki/Email#Header_fieldsShooin
C
1

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?

Connivent answered 4/10, 2014 at 3:21 Comment(2)
I was more looking for a way to use Mail.app to send the email without the user having to go through all the complexities of using low level protocols. I thought since other more basic headers such as title, etc. are allowed there should be a way to attach headers like In-Reply-To using a high level API somehow.Shooin
I was going to suggest that you pre-compose an email and open it using open -a mail.app myEmail, but then I remembered you're trying to do this for iOS. I think your best shot, short of exploiting private methods, would be to either a) swizzle out a later-executing, non-private method that allows you a bit of access to the model going out (not likely), b) roll your own mail compose view controller supported by one of several libraries mentioned throughout this qa. Apple simply did not expose what you are looking for. :/Connivent

© 2022 - 2024 — McMap. All rights reserved.