使用mailCore2发送电子邮件,给出错误代码= 30 [英] Sending emails using mailCore2 giving error code = 30

查看:2087
本文介绍了使用mailCore2发送电子邮件,给出错误代码= 30的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MailCore2框架发送电子邮件。我没有使用MFMailComposer,因为
的要求没有任何UI的电子邮件。我们只是收到电子邮件ID,点击按钮发送一些信息
到电子邮件地址。
这是我下面提到的代码

  func sendEmailToCustomer(emailid:String?)
{
让会话:MCOSMTPSession = MCOSMTPSession()
session.hostname =mail。***。com
session.port = 25
session.connectionType = MCOConnectionType.clear

let builder = MCOMessageBuilder()
builder.header.from = MCOAddress(displayName:iPad App,邮箱:INVESTOR@xxx.com)
builder.header.to = [ MCOAddress(displayName:iPad App,mailbox:emailid)]

builder.header.subject =电子邮件链接\(NSUserDefaults.standardUserDefaults()。valueForKey(branch_id)! b $ b builder.htmlBody =感谢您的选择,这是您希望在收件箱中的链接\\\
\((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?) - >无效

if(error!= nil){
//继续发送电子邮件,直到成功。出于安全考虑,需要知道。
// 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 {
//电子邮件发送成功。

打印(电子邮件发送成功\(emailid))
self.showAlertMessage(MESSAGE_EMAIL_SENT,标题:发送电子邮件,操作:[UIAlertAction(标题:OK :.Default){action in
}],withSound:false)

}
})
}
/ pre>

当我的到电子邮件在组织中时,它的工作正常。但是如果我尝试发送电子邮件到
以外的帐户,然后得到错误'错误域= MCOErrorDomain代码= 30'
我尝试更改不同的端口,连接类型。没有任何工作。请帮助

解决方案

您的问题与mailcore2无关,而是与您正在使用的邮件服务器相关。您收到的550外部中继拒绝的错误消息表示您要连接的邮件服务器未配置为允许您发送到其他域。
如果您认为配置错误,请与该smtp服务器的postmaster通讯。 (postmaster @,插入服务器的域,而不是)


I am using MailCore2 framework to send emails. I am not using MFMailComposer because the requirement is not to have any UI for email. We just getting email id and on click of button sending some information to email address. This is my code mentioned below

 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)

            }
        })
    }

When my "to" email is with in organization, its working fine. But if i try to send email to some outside account, then getting error 'Error Domain=MCOErrorDomain Code=30 ' I tried changing different Ports ,connection type . Nothing is working. Please help

解决方案

Your question is not related to mailcore2, but rather to the mailserver you are using. The error message you are getting '550 Denied for External Relay' means that the mail server you are connecting to is not configured to allow you to send to other domains. Talk to the postmaster of that smtp server if you believe that configuration to be in error. (postmaster@, insert the domain of the server instead of )

这篇关于使用mailCore2发送电子邮件,给出错误代码= 30的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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