iPhone SDK - Sending email

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

  1. macrumors newbie

    Joined:
    Jun 12, 2008
    #1
    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

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

    Joined:
    Jul 1, 2008
    #3
    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

    Consultant

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

    Joined:
    Jul 1, 2008
    #5
    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

    Joined:
    Feb 22, 2008
    #6
    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

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

    Joined:
    Jul 16, 2002
    Location:
    Dallas, TX
    #8
    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

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

    Joined:
    Sep 29, 2008
    #10
    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

    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

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11

    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

    Joined:
    Sep 29, 2008
    #12
    Still not working

    I changed the code to

    Code:
    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

    Joined:
    Sep 29, 2008
    #13
    it works in html

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

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #14
    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

    Joined:
    May 24, 2003
    #15
    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

    Joined:
    Sep 29, 2008
    #16
    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

    Joined:
    Aug 2, 2008
    #17
    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

    Joined:
    Sep 24, 2008
    #18
    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!

    bo

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

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #19
    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