Send email with attachment [mega-merged thread]

Discussion in 'iOS Programming' started by Rad, Jul 15, 2008.

  1. Rad macrumors regular

    Aug 8, 2006
    Anyone figure out how to send an email with an attachment via an iPhone app? The simple mailto: command may work with text only, but I need to be able to send something like a photo or drawing.

  2. asouns macrumors member

    Jun 29, 2008
  3. DSchwartz88 macrumors 6502

    May 18, 2006
    Using e-mail with attachments

    Hey All,

    There was another question like this before, but it was never fully answered. I need to get a photo that my UIImagePickerController grabs into an e-mail, that will send to a preset address. I have two questions:

    1. How do i get the e-mail message to pop up in the first place? What code would i have to implement to do so?

    2. How do i insert the image that i grabed before as an attachment?

    Im trying to make this very much like the MobileMe photo upload if anyone knows that.

    Any help would be appreciated.

  4. admanimal macrumors 68040

    Apr 22, 2005
    You can open a mail message just by sending a mailto URL to openURL. You can specify the body of the message but I'm not sure if there is an official way to do attachments.
  5. grimjim macrumors member

    May 24, 2003
    Yes, using the built-in to send emails is really easy. You just need to pass the email's details to the app delegate via its openURL: method, and it will deal with it all for you. Here's some sample code:

    UIApplication *theApplication = [UIApplication sharedApplication];
    NSString *recipient = [NSString stringWithString:@""];
    NSString *subject = [NSString stringWithString;@"The subject line"];
    NSString *body = [NSString stringWithString:@"This is a really dull email. Sorry."];
    NSString *s = [NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@", recipient, subject, body];
    NSString *mailString = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [[NSURL alloc] initWithString:mailString];
    [theApplication openURL:url];
    There are a couple of caveats, though:

    1. Because you are using, which is a separate application, your own application will close. So, users will need to send the message, then press the home button and fire up your app again.

    2. There is no means of adding an attachment using this method. Bummer.

    How to get around it? Well, the best way to work around both the problems would actually be to implement a very simple SMTP client inside your application. You could probably find code on the web that you could adapt. It would mean that you could send the mail from within your application, so it wouldn't need to close, and that you could implement the attachment of, um attachments. Good luck!
  6. amanbvp macrumors newbie

    Aug 8, 2008
    How to send email with attachment??

    hi all,
    I am searching for the solution so that my application can send an email with an attachment. I have used mailto: but it dosn't support attachment. It would be of great help if you provide me with some code or url.
  7. robbieduncan Moderator emeritus


    Jul 24, 2002
    As far as I can tell you can't. There is no method to send mail apart from the mailto: url. Whilst you can, in theory, pass additional mail headers into this the useful/interesting ones like Content-type are ignored. So, at least for this version of the SDK, you can only send mail with text contents.
  8. amanbvp macrumors newbie

    Aug 8, 2008
    How to implement SMTP client for sending email attachment??

    hi all,
    I am trying to build an application which can send email with attachment and I get to know that it is not possible to do that using mailto:.Hence i am trying to implement that by developing SMTP client but i am new to the SMTP hence i don't know where to start. Pls guide me where to start and is it possible on iphone.

    Thanks in advance
  9. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    SMTP RFC document.

    This should give you all the information you need to implement an SMTP client.
  10. arnieterm macrumors regular

    Aug 28, 2008
    How to implement it???

    As mailto does not allow you to add attachment to your email that to be sent from within your application on IPhone, I am looking for a simple SMTP mail client for IPhone.
    Can anybody provide any idea how to get started??
  11. CommanderData macrumors regular

    Dec 1, 2007
    The RFC2821 is definitely the place to get started reading. But you may go through a lot of trouble only to find they turn you down for implementing e-mail functionality in your app. I'm only aware of one app that made it through, the one that talks to Microsoft's Hotmail/Live servers (forget the name at the moment). I think that was because it did not conflict with Apple's interests (they had no intent to ever support Hotmail/Live protocols).
  12. dougdawson macrumors member

    Aug 24, 2008
    Austin, TX
    I don't see anything in the NDA that prevents you from sending data via e-mail, provided that you are only using the public SDK. In fact, the networking facilities in the public SDK are very rich, and you can do a lot with them.

    Where you might have a problem is with implementing


Share This Page