PDA

View Full Version : Send email with attachment [mega-merged thread]




Rad
Jul 15, 2008, 12:02 PM
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!



asouns
Jul 17, 2008, 03:27 AM
same question here

DSchwartz88
Jul 26, 2008, 12:01 AM
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
Jul 26, 2008, 12:10 AM
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
Jul 28, 2008, 03:09 PM
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:

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
Aug 31, 2008, 02:40 AM
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
Aug 31, 2008, 02:51 AM
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
Aug 31, 2008, 06:12 AM
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

Cromulent
Aug 31, 2008, 07:02 AM
SMTP RFC document (http://www.ietf.org/rfc/rfc2821.txt).

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

arnieterm
Nov 4, 2008, 05:17 AM
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

Pring
Nov 4, 2008, 05:28 AM
http://www.ietf.org/rfc/rfc2821.txt

CommanderData
Nov 4, 2008, 05:40 AM
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
Nov 4, 2008, 12:38 PM
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