views:

58

answers:

3

Ok,

The regular protocal used to send email from a form on iPhone (from what I know) is to send it via the Mail application. This code here:

-(IBAction)sendEmail {

    NSString *url = [NSString stringWithFormat: @"mailto:%@?body=%@", toEmail.text, content.text];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

    //status.text = @"Sending...";
}

Now, I want it to be a form where it just sends the email. I don't want it to go through Mail or anything, and I want it to send from a predefined address such as [email protected] for example.

How would I do this?

Thank you in advance.

Alex

+1  A: 

In your case, I would recommend you to use an MFMailComposeViewController it's very easy to integrate. I'm not sure tough if it's possible to write emails from a predefined adress (I guess sending an email in that way uses the default mail account of the users device).

for more flexibility, i guess you have to go with SMTP.

what I do in my project is:

-(void)displayComposerSheet{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:NSLocalizedString(@"MailSubject", @"")];
NSString *emailBody = NSLocalizedString(@"MailBody", @"");
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];

}

there are also a few delegate-methods that you can handle. everything relevant to MFMailComposeViewController you'll find here MFMailComposeViewController Class Reference

samsam
A: 

Look at http://howtopingwithyourtelephone.blogspot.com

Wilmaha
A: 

The MFMailCompose does seem to mail from your devices default account.

I use this bit of code in my Implementation file to send a feed back email to a predefined address I want them to send to.

It is set to a button that presents the view when clicked.

-(IBAction) Feedback:(id)sender {
        NSArray *toRecipients = [NSArray arrayWithObject:@"xxxxxxxx"];
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
        picker.navigationBar.tintColor = [UIColor colorWithRed:.0 green:.1706 blue:.3804 alpha:1];
        [picker setToRecipients:(NSArray *)toRecipients];
        [picker setSubject:@"Feedback"];

        [self presentModalViewController:picker animated:YES];
        [picker release];


}

I placed the x's where I would have the email address. This code also tints the navigationbar in which my mail form comes up in.

This requires the MessageUI and MFMailComposerDelegate.

You can include multiple email addresses to send too also if you need to since it builds them in an array.

Rugluds