MailCore2的电子邮件帐户 [英] Email Account For MailCore2

查看:178
本文介绍了MailCore2的电子邮件帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含MailCore2 API的Swift通用应用程序。它在调试和发布模式下都能很好地工作。当我要求加利福尼亚州的一位朋友进行测试时,会弹出警告视图并显示错误消息。我发现原因是因为我使用Google作为我发送电子邮件的帐户。



这是我的代码:

  var smtpSession = MCOSMTPSession() 
smtpSession.hostname =smtp.gmail.com
smtpSession.username =matt@gmail.com
smtpSession.password =xxxxxxxxxxxxxxxx
smtpSession.port = 465
smtpSession.authType = MCOAuthType.SASLPlain
smtpSession.connectionType = MCOConnectionType.TLS
smtpSession.connectionLogger = {(connectionID,type,data)in
if data!= nil {
if string = NSString(data:data,encoding:NSUTF8StringEncoding){
NSLog(Connectionlogger:\(string))
}
}
}

var builder = MCOMessageBuilder()
builder.header.to = [MCOAddress(displayName:Rool,mailbox:itsrool@gmail.com)]
builder.header .from = MCOAddress(displayName:Matt R,mailbox:matt@gmail.com)
builder.header.subject =我的消息
builder.htmlBody =Yo Rool,这是一个测试消息!

让rfc822Data = builder.data()
让sendOperation = smtpSession.sendOperationWithData(rfc822Data)
sendOperation.start {(error) - >无效
if(error!= nil){
NSLog(Error sending email:\(error))
} else {
NSLog(发送成功! )
}
}

Google禁止发送电子邮件,因为它认为劫持者试图访问我的帐户(因为我通常登录时处于不同的状态)。



我的问题是:是否有防止谷歌阻止这些电子邮件被发送?我希望人们能够发送电子邮件,无论他们位于何处。如果这是不可能的,他们是否有一个电子邮件服务,不会阻止因为您(用户)从不同位置登录而发送电子邮件?

感谢所有回覆的人。

解决方案

这一款适合我,希望它也适用于您,试试这个,

  let smtpSession:MCOSMTPSession = MCOSMTPSession()
smtpSession.hostname =smtp.gmail.com
smtpSession.port = 465
smtpSession.username =abc@gmail.com
smtpSession.password =xxxxx
smtpSession.authType = MCOAuthType.SASLPlain
smtpSession.connectionType = MCOConnectionType.TLS

let builder:MCOMessageBuilder = MCOMessageBuilder()
让:from:MCOAddress = MCOAddress(displayName:abc,mailbox:abc@gmail.com)
让:MCOAddress = MCOAddress(displayName :无,邮箱:abc@gmail.com)
builder.header.from =从
builder.header.to = [to]
builder.header.subject =My Messgae
builder.htmlBody =这是测试消息
让rcf822Data:NSData = builder.data()
让sendOperation:MCOSMTPSendOperation = smtpSession.sendOp erationWithData(rcf822Data)
sendOperation.start {(error:NSError?)in
if(error!= nil){
print(Error Sending Mail:\(error))
} else {
print(Mail Sent Successfully)
}
}


I have created a Swift universal app that incorporates the MailCore2 API. It works perfectly on both debug and release mode. When I asked a friend in California to test it out, an alert view popped up with an error message. I found out that the reason for this was because I was using Google as the account I was emailing from.

Here is my code:

var smtpSession = MCOSMTPSession()
smtpSession.hostname = "smtp.gmail.com"
smtpSession.username = "matt@gmail.com"
smtpSession.password = "xxxxxxxxxxxxxxxx"
smtpSession.port = 465
smtpSession.authType = MCOAuthType.SASLPlain
smtpSession.connectionType = MCOConnectionType.TLS
smtpSession.connectionLogger = {(connectionID, type, data) in
    if data != nil {
        if let string = NSString(data: data, encoding: NSUTF8StringEncoding){
            NSLog("Connectionlogger: \(string)")
        }
    }
}

var builder = MCOMessageBuilder()
builder.header.to = [MCOAddress(displayName: "Rool", mailbox: "itsrool@gmail.com")]
builder.header.from = MCOAddress(displayName: "Matt R", mailbox: "matt@gmail.com")
builder.header.subject = "My message"
builder.htmlBody = "Yo Rool, this is a test message!"

let rfc822Data = builder.data()
let sendOperation = smtpSession.sendOperationWithData(rfc822Data)
sendOperation.start { (error) -> Void in
    if (error != nil) {
        NSLog("Error sending email: \(error)")
    } else {
        NSLog("Successfully sent email!")
    }
} 

Google prevented the email from being sent because it thought a hijacker was trying to access my account (being that I am in a different state when I normally log in.)

My question is: Is there a way of preventing Google from blocking these emails from being sent? I would like people to be able to send emails, no matter where they are located. If this isn't possible, them is there an emailing service that doesn't prevent emails from being sent just because you (the users) are logging in from a different location?

Thanks in advance to all who reply.

解决方案

this one works for me, hope it works for you too, try this,

    let smtpSession:MCOSMTPSession = MCOSMTPSession()
    smtpSession.hostname = "smtp.gmail.com"
    smtpSession.port = 465
    smtpSession.username = "abc@gmail.com"
    smtpSession.password = "xxxxx"
    smtpSession.authType = MCOAuthType.SASLPlain
    smtpSession.connectionType = MCOConnectionType.TLS

    let builder:MCOMessageBuilder = MCOMessageBuilder()
    let from:MCOAddress = MCOAddress(displayName: "abc", mailbox: "abc@gmail.com")
    let to:MCOAddress = MCOAddress(displayName: nil, mailbox: "abc@gmail.com")
    builder.header.from = from
    builder.header.to = [to]
    builder.header.subject = "My Messgae"
    builder.htmlBody = "This is test message"
    let rcf822Data:NSData = builder.data()
    let sendOperation:MCOSMTPSendOperation = smtpSession.sendOperationWithData(rcf822Data)
    sendOperation.start { (error:NSError?) in
        if (error != nil) {
            print("Error Sending Mail : \(error)")
        }else{
            print("Mail Sent Successfully")
        }
    }

这篇关于MailCore2的电子邮件帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆