Send email with attachment [mega-merged thread]

Discussion in 'iPhone/iPad Programming' started by Rad, Jul 15, 2008.

  1. Rad
    macrumors regular

    Joined:
    Aug 8, 2006
    #1
    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.

    Thanks!
     
  2. macrumors member

    Joined:
    Jun 29, 2008
    #2
    same question here
     
  3. macrumors 6502

    Joined:
    May 18, 2006
    #3
    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.

    Daniel
     
  4. macrumors 68040

    Joined:
    Apr 22, 2005
    #4
    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. macrumors member

    Joined:
    May 24, 2003
    #5
    Yes, using the built-in Mail.app 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:

    Code:
    UIApplication *theApplication = [UIApplication sharedApplication];
    
    NSString *recipient = [NSString stringWithString:@"someone@somewhere.com"];
    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 Mail.app, 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. macrumors newbie

    Joined:
    Aug 8, 2008
    #6
    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. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    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. macrumors newbie

    Joined:
    Aug 8, 2008
    #8
    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. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    SMTP RFC document.

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

    Joined:
    Aug 28, 2008
    #10
    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??
    Thanks
     
  11. macrumors 6502

    Joined:
    Sep 17, 2003
  12. macrumors regular

    Joined:
    Dec 1, 2007
    #12
    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).
     
  13. macrumors member

    Joined:
    Aug 24, 2008
    Location:
    Austin, TX
    #13
    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 YAMail.app.

    Doug
     

Share This Page