SMTP:发送邮件时发生错误

时间:2015-01-07 17:42:21

标签: mailcore2

我通过OAuth和IMAP / SMTP在我的iOS应用中使用Gmail。如果我使用另一个帐户虽然SMTP不起作用。我已尝试在自定义域(通过Host Gator)和outlook.com帐户上使用电子邮件帐户。 IMAP工作正常,只是发送失败。我检查了连接记录器并获得以下内容:

event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 220 BLU436-SMTP189.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at  Wed, 7 Jan 2015 04:03:35 -0800 

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: EHLO -iPad

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 250-BLU436-SMTP189.smtp.hotmail.com Hello [80.194.198.170]

250-TURN

250-SIZE 41943040

250-ETRN

250-PIPELINING

250-DSN

250-ENHANCEDSTATUSCODES

250-8bitmime

250-BINARYMIME

250-CHUNKING

250-VRFY

250-TLS

250-STARTTLS

250 OK

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: STARTTLS

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 220 2.0.0 SMTP server ready

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: EHLO -iPad

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 250-BLU436-SMTP189.smtp.hotmail.com Hello [80.194.198.170]

250-TURN

250-SIZE 41943040

250-ETRN

250-PIPELINING

250-DSN

250-ENHANCEDSTATUSCODES

250-8bitmime

250-BINARYMIME

250-CHUNKING

250-VRFY

250-AUTH LOGIN PLAIN XOAUTH2

250 OK

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 2 withData: AUTH PLAIN a21jZ3JhZHlAb3V0bG9vay5jb20Aa21jZ3JhZHlAb3V0bG9vay5jb20AQWZ0ZXJlZmZlY3RzMT8=

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 235 2.7.0 Authentication succeeded

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: MAIL FROM:<myemail@outlook.com>

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 250 2.1.0 myemail@outlook.com....Sender OK

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: RCPT TO:<email@invalid.com>

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 250 2.1.5 email@invalid.com 

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: MAIL FROM:<myemail@outlook.com> SIZE=799

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 0 withData: 503 5.5.2 Sender already specified

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 
event logged:0x18141580 1 withData: QUIT

event logged:0x18141580 -1 withData: 
event logged:0x18141580 -1 withData: 

我的SMTP设置为:

电子邮件

密码

港口25(也尝试过587)

MCOConnectionTypeStartTLS(也尝试过MCOConnectionTypeTLS)

MCOAuthTypeSASLNone

在sendOperationWithData中:我收到以下错误:Error Domain=MCOErrorDomain Code=30 "An error occured while sending the message."

这是要发送的代码:

  MCOAddress *address= [MCOAddress addressWithDisplayName:currentAccount.name mailbox:smtp_email];

MCOSMTPOperation * op = [currentSMTPSession checkAccountOperationWithFrom:address];
        [op start:^(NSError * error) {

            }

我配置SMTP(在发送操作之前调用),如下所示:

    if (currentSMTPSession == nil) {
    currentSMTPSession = [[MCOSMTPSession alloc] init];
}

[currentSMTPSession setHostname:currentAccount.smtp_server];
[currentSMTPSession setUsername:currentAccount.smtp_email];
[currentSMTPSession setPassword:currentAccount.smtp_password];
[currentSMTPSession setPort:currentAccount.smtp_port.intValue];
[currentSMTPSession setConnectionType:MCOConnectionTypeStartTLS];
[currentSMTPSession setOAuth2Token:currentAccount.oauthToken];
[currentSMTPSession setAuthType:MCOAuthTypeSASLNone]

1 个答案:

答案 0 :(得分:2)

问题在于连接类型。当我创建帐户时,我保存了使用MCONetService返回的连接类型。在我之前处理代码库的人是保存IMAP连接类型而不是SMTP连接类型。我改变了这个,现在它起作用了。

我也遵循了@DinhVietHoá的建议并删除了checkAccountOperationWithForm: