【问题标题】:mailcore2 via SMTP Outlook.com gives Error Domain=MCOErrorDomain Code=1 "A stable connection to the server could not be established."mailcore2 通过 SMTP Outlook.com 给出 Error Domain=MCOErrorDomain Code=1 “无法建立与服务器的稳定连接。”
【发布时间】:2016-04-04 23:11:48
【问题描述】:

我正在使用 Objective-C 在 iOS9 上使用 mailcore2 设置 Outlook.com。我的 gmail 已经在使用 imap 和 smtp。我可以从 outlook.com 获取电子邮件,但是当我尝试发送电子邮件时,我收到以下错误:

Error Domain=MCOErrorDomain Code=1 "与服务器的稳定连接 无法建立。”

下面是我的代码示例:

MCOSMTPSession *session = [[MCOSMTPSession alloc] init];
[session setAuthType:MCOAuthTypeXOAuth2Outlook];
[session setOAuth2Token:accessToken];
[session setUsername:@"user@outlook.com"];
[session setHostname:@"smtp-mail.outlook.com"];
[session setPort:25];  //also tried 587
[session setConnectionType:MCOConnectionTypeStartTLS];  //Also tried MCOConnectionTypeTLS and MCOConnectionTypeClear
[session setCheckCertificateEnabled:false];

MCOSMTPSendOperation *sendOperation = [session sendOperationWithData:data];
[sendOperation start:^(NSError *error) {
}];

我也尝试了checkAccountOperationWithFrom 操作,但也出现了同样的错误。

【问题讨论】:

标签: ios objective-c smtp mailcore2 outlook.com


【解决方案1】:

我无法从 Outlook 获取电子邮件,您能告诉我在 Imap 设置中要进行哪些更改。以下是我正在使用的代码..

session = [[MCOIMAPSession alloc]init];
session.hostname = @"imap-mail.outlook.com";
session.username = @"dummy@outlook.com";
session.password = nil;
session.port = 993;
session.OAuth2Token = accessToken;
session.connectionType = MCOConnectionTypeStartTLS;
session.authType = MCOAuthTypeSASLLogin;
session.checkCertificateEnabled = false;

【讨论】:

    【解决方案2】:

    Swift 5、iOS 13、Xcode 版本 11.3.1 (11C504)

    Also Need to Disable Captcha :  [https://accounts.google.com/DisplayUnlockCaptcha][1]
    

    回复:邮件发送成功!

    这里是完美的解决方案:

        @IBAction func btnSendMailClicked(_ sender: UIButton) {
    
        print(#function)
        let smtpSession = MCOSMTPSession()
        smtpSession.hostname = "smtp.gmail.com"
        smtpSession.username = "emailaddress@gmail.com"
        smtpSession.password = "password" //You can create [App Password from gmail setting][1] 
    
        smtpSession.port = 587 //25
        smtpSession.authType = MCOAuthType.saslPlain
        smtpSession.connectionType = MCOConnectionType.startTLS
        smtpSession.isCheckCertificateEnabled = false
    
        smtpSession.connectionLogger = {(connectionID, type, data) in
            if data != nil {
                if let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){
                    NSLog("Connectionlogger: \(string)")
                }
            }
        }
    
        let builder = MCOMessageBuilder()
        builder.header.to = [MCOAddress(displayName: "Swifty Developers", mailbox: "swiftydevelopers@gmail.com")!]
        builder.header.from = MCOAddress(displayName: "Mehul Parmar", mailbox: "mehulasjack@gmail.com")
        builder.header.subject = "My message"
        builder.htmlBody = "Yo Rool, this is a test message!"
    
        let rfc822Data = builder.data()
        let sendOperation = smtpSession.sendOperation(with: rfc822Data)
        sendOperation?.start { (error) -> Void in
            if (error != nil) {
                NSLog("Error sending email: \(String(describing: error))")
            } else {
                NSLog("Successfully sent email!")
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-06
      • 2018-11-28
      • 2015-06-13
      • 2018-05-13
      • 2017-08-31
      • 2016-12-21
      • 2020-04-06
      • 1970-01-01
      • 2012-10-17
      相关资源
      最近更新 更多