我正在使用MailCore2框架发送电子邮件。我没有使用MFMailComposer因为要求 没有任何电子邮件用户界面。我们只是获取电子邮件ID,点击按钮发送一些信息 电子邮件地址。 这是我下面提到的代码
func sendEmailToCustomer(emailid:String?)
{
let session : MCOSMTPSession = MCOSMTPSession()
session.hostname = "mail.***.com"
session.port = 25
session.connectionType = MCOConnectionType.clear
let builder = MCOMessageBuilder()
builder.header.from = MCOAddress(displayName: " iPad App", mailbox:"INVESTOR@xxx.com")
builder.header.to = [MCOAddress(displayName: "iPad App", mailbox:emailid)]
builder.header.subject = "Email Link \(NSUserDefaults.standardUserDefaults().valueForKey("branch_id")!)"
builder.htmlBody = "Thanks for choosing . Here is link you wanted to have in your inbox \n \((webView.request?.URL?.absoluteString)!))"
let data = builder.data()
let sendOperation : MCOSMTPSendOperation = session.sendOperationWithData(data)
NSUserDefaults .standardUserDefaults().setValue(emailid, forKey: "Customer_EmailId")
sendOperation.start({
(error : NSError?) -> Void in
if(error != nil){
//Keep sending the email till it succeeds. needs to know for security reasons.
// self.sendEmailToCustomer(emailid)
print("customer email failed.\(error?.code) \(error)")
self.showAlertMessage(MESSAGE_EMAIL_Not_SENT, title:"Email Not Sent", actions: [UIAlertAction(title: "OK", style: .Default) {action in
}], withSound: false)
Crittercism.leaveBreadcrumb("customer email failed")
}
else{
//Email sent successfully.
print("Email sent successfully \(emailid)")
self.showAlertMessage(MESSAGE_EMAIL_SENT, title:"Email Sent", actions: [UIAlertAction(title: "OK", style: .Default) {action in
}], withSound: false)
}
})
}
当我的“to”电子邮件在组织中时,它的工作正常。但是如果我尝试向外面的某些人发送电子邮件 帐户,然后收到错误'错误域= MCOErrorDomain代码= 30' 我尝试更改不同的端口,连接类型。什么都行不通。请帮忙
答案 0 :(得分:0)
您的问题与mailcore2无关,而是与您正在使用的邮件服务器有关。您收到的错误消息' 550拒绝外部中继'表示您要连接的邮件服务器未配置为允许您发送到其他域。 如果您认为配置有误,请与该smtp服务器的postmaster联系。 (postmaster @,插入服务器的域而不是)