Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Rad

macrumors regular
Original poster
Aug 8, 2006
130
14
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!
 

DSchwartz88

macrumors 6502
May 18, 2006
419
0
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
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
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.
 

grimjim

macrumors member
May 24, 2003
75
0
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!
 

amanbvp

macrumors newbie
Aug 8, 2008
5
0
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

amanbvp

macrumors newbie
Aug 8, 2008
5
0
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
 

arnieterm

macrumors regular
Aug 28, 2008
201
0
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
 

CommanderData

macrumors 6502
Dec 1, 2007
250
3
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).
 

dougdawson

macrumors member
Aug 24, 2008
62
0
Austin, TX
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).

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.