iPhone SDK - Sending email

Discussion in 'iOS Programming' started by tnash, Jun 12, 2008.

  1. macrumors newbie

    Jun 12, 2008
    Anyone know if it is possible to send and email from within a custom app on the iPhone (i.e. using the sdk to call the iPhone email application or some other means).

    You can interact with the contacts and calendar, can you interact with email?
  2. macrumors G3

    Jul 25, 2007
    yes, you create a mailto: url (which can include subject and body) and launch it.
  3. macrumors newbie

    Jul 1, 2008
    Send email with attachment

    Is there a way to send an email from an iphone app and include an attachment? Please help, this must be common.
  4. macrumors G5


    Jun 27, 2007
    No, you cannot make an app to send s-p-a-m from the iPhone.
  5. macrumors newbie

    Jul 1, 2008
    I'm not trying to send s-p-a-m I'm trying to create an legit iPhone app for download through the app store. Anyone have real solutions?
  6. macrumors newbie

    Feb 22, 2008
    I'm resurrecting this post because, like tnash, I would like my app to launch Mail so that an email can be sent... but I'm not sure how to do that.
  7. macrumors regular

    Apr 4, 2007
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:email@email.com?subject=Hello"]];
  8. macrumors member

    Jul 16, 2002
    Dallas, TX
    Applications like Safari and the Photo app launch a sliding new message panel when you want to send an email. Is this possible to set up using the third party SDK rather than launching the entire Mail application?
  9. macrumors newbie

    Feb 22, 2008
    I'm not aware of a way. I don't think that's possible yet.
  10. macrumors newbie

    Sep 29, 2008
    Does this work in the simulator

    I tired using mailto url but the mail application did not launch in the iPhone simulator. I added a button to my view and in the delegate method for touch up inside i had the following code

    NSURL *url = [[NSURL alloc] initWithString:@"mailto:k@yahoo.com?subject=This is my subject&body=this is the body"];
    [[UIApplication sharedApplication] openURL:url];

    This did not launch the mail application. Earlier i had the wrong url for mailto , i got an alert saying could not process url. But now nothing happens.
  11. Moderator emeritus


    Jul 24, 2002

    That doesn't look like a valid URL to me: you can't have spaces in URLs. I think you might well want to encode it. Perhaps stringByAddingPercentEscapesUsingEncoding: might be of help?
  12. macrumors newbie

    Sep 29, 2008
    Still not working

    I changed the code to

    NSURL *url = [[NSURL alloc] initWithString:@"mailto:k@yahoo.com?subject=subject&body=body"];
    [[UIApplication sharedApplication] openURL:url];
    Now i get unsupported url.
  13. macrumors newbie

    Sep 29, 2008
    it works in html

    <a href="mailto:k@yahoo.com?subject=subject&body=body">blah</a> 
  14. macrumors 68000

    Feb 12, 2008
    I've used the same code and got it to work on the device. I was under the impression that it didn't work in the simulator because there is no mail app on it.
  15. macrumors member

    May 24, 2003
    You're absolutely correct. The simulator will always complain that it doesn't know what to do with a mailto: URL. If you think you've got it right, the only way to test it for sure is on a device.
  16. macrumors newbie

    Sep 29, 2008
    What happens to ur app

    I dont have access to a device currently. I was trying to find out whether my application will shutdown if i call the email app using mailto url. Same for calling a phone number does it shutdown my app if i use tel url to call a number.
  17. macrumors newbie

    Aug 2, 2008
    We open the email app from our app using a mailto url and it does shut it down. The user has to re-launch our app after they've finished sending the email.
  18. macrumors newbie

    Sep 24, 2008
    Answer to: 'error when launching'

    You cannot try it in the simulator, to test this out you have to install it on the iPhone. If you get the message, "could not process request" its probably the issue.

    Install on the iPhone and there you go!


    wyzfam :apple: tMiMP :apple: tCiMP :apple: My Baby Signs
  19. macrumors 604

    Jul 29, 2003
    Silicon Valley
    You might be able to test it on the Simulator by writing test stub apps that register themselves to handle the mailto: and tel: URLs.


Share This Page