gpt4 book ai didi

ios - 使用 iOS 向自己发送电子邮件。

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:09:27 24 4
gpt4 key购买 nike

我曾通过 messageUIFramework 使用 MFMailComposeViewController。我有一个案例,我必须向自己发送电子邮件。我如何添加“发件人”地址 MFMailComposeViewController 委托(delegate)?有什么建议么?

最佳答案

如何在APP内发送邮件?

- (IBAction)sendMail:(id)sender {
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

mailer.mailComposeDelegate = self;

[mailer setSubject:@"Message Pro"];

//Destination adress
NSArray *toRecipients = [NSArray arrayWithObjects:@"your adress", nil];
[mailer setToRecipients:toRecipients];

//Attachement Object
UIImage *myImage = [UIImage imageNamed:@"image.jpeg"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"mobiletutsImage"];

//Message Body
NSString *emailBody = @"message body";
[mailer setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:mailer animated:YES];

[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(@"Mail not sent.");
break;
}

// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}

不要忘记

  1. 使用 IBAction 添加一个按钮 = sendMail
  2. 导入MessageUI.framework
  3. 在您的 .h 文件中添加委托(delegate) MFMailComposeViewControllerDelegate

关于ios - 使用 iOS 向自己发送电子邮件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11607489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com