繁体   English   中英

System.Net.Mail.SmtpException:邮箱不可用

[英]System.Net.Mail.SmtpException: Mailbox unavailable

// CREATE NEW EMAIL OBJECT
ContactUs.Core.Email oEmail = new ContactUs.Core.Email();

// EMAIL SMTP SERVER INFORMATION
oEmail.SmtpServer = "Server";
oEmail.SetAuthentication("Email", "Password");

// EMAIL INFORMATION
oEmail.From = "contact@Server.com";
oEmail.To = "RecipientEmail";
oEmail.Subject = this.txtMessage.Text;
oEmail.Message = strMessage;

// SEND EMAIL
oEmail.HtmlFormat = true;
oEmail.Send();

这是我得到的错误。 我知道身份验证是正确的。

System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ContactUs.Core.Email.Send()
at _Default.btnSend_Click(Object sender, EventArgs e)

5.7.1 ==禁止中继

您需要允许中继经过身份验证的用户,或者从SMTP服务器的IP地址范围进行中继: http : //support.microsoft.com/kb/304897

您使用哪种服务器中继消息?

您必须在SMTP身份验证中将用户名设置为contact@Server.com

        // CREATE NEW EMAIL OBJECT
        ContactUs.Core.Email oEmail = new ContactUs.Core.Email();

        // EMAIL SMTP SERVER INFORMATION
        oEmail.SmtpServer = "Server";
        oEmail.SetAuthentication("contact@Server.com", "Password");

        // EMAIL INFORMATION
        oEmail.From = "contact@Server.com";
        oEmail.To = "RecipientEmail";
        oEmail.Subject = this.txtMessage.Text;
        oEmail.Message = strMessage;

        // SEND EMAIL
        oEmail.HtmlFormat = true;
        oEmail.Send();

SMTP服务器不允许您设置与oEmail.From(发件人的电子邮件地址)不同的凭据用户名。

将网络凭据添加到您的代码。

样本邮件代码:

private void SendMailViaGmailUsingCredentials()
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("your_email_address@gmail.com");
                mail.To.Add("to_address@mfc.ae");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM