【发布时间】:2016-06-22 05:05:04
【问题描述】:
我正在尝试发送昨天的邮件,但发送失败。总是收到这个错误 发送电子邮件时出错:Error Domain=MCOErrorDomain Code=1“无法建立与服务器的稳定连接。” UserInfo={NSLocalizedDescription=无法建立与服务器的稳定连接。}
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.emailimage)];
//Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [imageData base64EncodedString];
//userdefaults
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *userName = [prefs stringForKey:@"username"];
NSString *password = [prefs stringForKey:@"password"];
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname =@"smtp.gmail.com";
//
smtpSession.port = 465;
smtpSession.username =userName;
smtpSession.password =password;
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType =MCOConnectionTypeStartTLS;
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from1 = [MCOAddress addressWithDisplayName:@""
mailbox:userName];
MCOAddress *to1 = [MCOAddress addressWithDisplayName:nil
mailbox:self.to.text];
[[builder header] setFrom:from1];
[[builder header] setTo:@[to1]];
[[builder header] setSubject:self.subject.text];
NSDate *now = [NSDate date];
double seconds1 = [now timeIntervalSince1970];
NSNumber *seconds = [NSNumber numberWithInteger:seconds1];
NSLog(@"id is=======================%@",seconds);
AppDelegate *tokenD = [[UIApplication sharedApplication]delegate];
NSLog(@"token in Composeviewcontroller %@",tokenD.Dtoken);
NSString *htmlbody1;
htmlbody1=@"abc";
[builder setHTMLBody:htmlbody1];
MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:self.filename];
[builder addAttachment:attachment];
NSData * rfc822Data = [builder data];
MCOSMTPSendOperation *sendOperation =
[smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
NSLog(@"Entered");
if(error) {
NSLog(@"Error sending email: %@", error);
}
else {
NSLog(@"Successfully sent email!");
}
}];
总是进入错误块和错误并收到错误发送电子邮件时出错:Error Domain=MCOErrorDomain Code=1
【问题讨论】:
-
使用
smtpSession.connectionType =MCOConnectionTypeTLS; -
也尝试过,但没有成功
标签: ios iphone gmail-api mailcore2