TechChain
TechChain

Reputation: 8952

Issue in sending email from iOS device?

I want to send the email from my iOS device programtically using iOS.I am using the below code to send the email but i don't know where to enter from field.From which email id the mail will be sent?

Code for Sending email in iOS

// Email Subject
    if(![MFMailComposeViewController canSendMail])
    {
        UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support Email!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [warningAlert show];
        return;

    }
    NSString *emailTitle = @"Test Email";
    // Email Content
    NSString *messageBody = @"iOS programming is so fun!";
    // To address
    NSArray *toRecipents = [NSArray arrayWithObject:@"support@appcoda.com"];

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
    [mc setSubject:emailTitle];
    [mc setMessageBody:messageBody isHTML:NO];
    [mc setToRecipients:toRecipents];

    // Present mail view controller on screen
    [self presentViewController:mc animated:YES completion:NULL];

Upvotes: 0

Views: 164

Answers (2)

Mike Gledhill
Mike Gledhill

Reputation: 29213

Just to add, one other thing you can't do using the built-in MFMailComposeViewController class is to send emails silently, without the full-screen "Compose email" view appearing.

In my app, I resorted to sending the email details (To address, Body text, etc) to my app's WCF web service, and getting that to send the email instead.

And, of course, doing it that way, you can choose which From address you wish to use.

Upvotes: 1

Popeye
Popeye

Reputation: 12123

You cannot actually set the From field when using the MFMailComposeViewController. What actually happens is the From field will default to whatever email account the user has specified to be used as the default email account on the device in the settings.

Upvotes: 0

Related Questions