gpt4 book ai didi

ios - 如何在不打开 MailComposer 或 objective-c 中的新 View 的情况下通过代码发送邮件

转载 作者:搜寻专家 更新时间:2023-10-30 20:24:27 25 4
gpt4 key购买 nike

-(IBAction)addbtnClick:(id)sender
{
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self;

[mailCont setSubject:@"yo!"];
[mailCont setToRecipients:@[@"address@example.com"]];
[mailCont setMessageBody:@"Don't ever want to give you up" isHTML:YES];

[self presentViewController:mailCont animated:YES completion:nil];

}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
//handle any error
[controller dismissViewControllerAnimated:YES completion:nil];
}

我有一个这样的代码可以工作。但是我不想打开 MFMailComposer。我只想点击按钮直接发送邮件。此代码打开 MFMailComposer。我不想打开它。请帮助。

最佳答案

检查下面的链接:--

SKPSMTPMessage

这个用于在没有任何用户交互的情况下在后台发送邮件...

使用下面的代码来使用这个库...

SKPSMTPMessage *emailMessage = [[SKPSMTPMessage alloc]init];
emailMessage.fromEmail = @"SENDER MAIL ID";
emailMessage.toEmail = @"RECEIPENT MAIL ID";
emailMessage.relayHost = @"smtp.gmail.com";
emailMessage.requiresAuth = YES;

您用于发送电子邮件的电子邮件的登录凭据

emailMessage.login = @"YOUR EMAIL ID";
emailMessage.pass = @"PASSWORD OF YOUR MAIL ACCOUNT";
emailMessage.subject = @"YOUR SUBJECT TO SEND MAIL";
emailMessage.wantsSecure = YES;
emailMessage.delegate = self;

NSString *password = @"PASSWORD";

NSString *message = [NSString stringWithFormat:@"Your password is : %@", password];

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain", kSKPSMTPPartContentTypeKey, message, kSKPSMTPPartMessageKey, @"8bit" , kSKPSMTPPartContentTransferEncodingKey, nil];

[emailMessage setParts:[NSArray arrayWithObjects:plainPart, nil]];
[emailMessage send];

希望这对你有帮助...

您必须提供您/公司电子邮件的登录电子邮件和密码,您要从中发送邮件...

emailMessage.login = @"YOUR EMAIL ID";
emailMessage.pass = @"PASSWORD OF YOUR MAIL ACCOUNT";

关于ios - 如何在不打开 MailComposer 或 objective-c 中的新 View 的情况下通过代码发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37923381/

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