你会如何在应用程序中发送swift电子邮件?比如说,例如你的用户希望在Parse(或不是)的社交媒体应用程序中重置他们的密码,但是你不想使用MessageUI,因为你希望它是自动的.我已经做了一些研究,发现它可以用mailgun,但我无法弄清楚如何使用它与swift和XCode 6.你能帮帮我吗?
我最近将MailCore2合并到了我的Objective-C项目中,并且它运行得很好.现在,我正在将应用程序中的代码转换为Swift.我已成功将MailCore2 API导入到我的swift项目中,但我没有看到如何将以下工作的Objective-C代码转换为Swift代码的文档(Google搜索,libmailcore.com,github):
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;
smtpSession.username = @"matt@gmail.com";
smtpSession.password = @"password";
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType = MCOConnectionTypeTLS;
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R"
mailbox:@"matt@gmail.com"];
MCOAddress *to = [MCOAddress addressWithDisplayName:nil
mailbox:@"hoa@gmail.com"];
[[builder header] setFrom:from];
[[builder header] setTo:@[to]];
[[builder header] setSubject:@"My message"];
[builder setHTMLBody:@"This is a test message!"];
NSData * rfc822Data = [builder data];
MCOSMTPSendOperation *sendOperation =
[smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
if(error) {
NSLog(@"Error sending …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我有一个简单的表单来收集数据,然后想要将包含该数据的电子邮件发送到特定的电子邮件地址.
理想情况下,我只是希望这对用户透明 - 他们只需按提交/发送,电子邮件将自动创建并在后台发送到该电子邮件地址,用户不知道.
我正在使用Objective-C获得这方面的教程,但我想使用Swift实现它.
是否有推荐的方式在后台发送电子邮件?