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

发布于 2024-11-27 09:35:12 字数 1226 浏览 0 评论 0原文

// 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 = "[email protected]";
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)
// 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 = "[email protected]";
oEmail.To = "RecipientEmail";
oEmail.Subject = this.txtMessage.Text;
oEmail.Message = strMessage;

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

This is the error I am getting. I know that the authentication is correct.

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三生一梦 2024-12-04 09:35:12

5.7.1 == 禁止中继

您需要允许经过身份验证的用户或来自 SMTP 服务器的一系列 IP 进行中继: http://support.microsoft.com/kb/304897

您使用什么类型的服务器来中继消息?

5.7.1 == relaying prohibited

You need to allow relaying for authenticated users, or from a range of IPs from your SMTP server: http://support.microsoft.com/kb/304897

What kind of server are you using to relay the messages?

时光磨忆 2024-12-04 09:35:12

您必须在 SMTP 身份验证中将用户名设置为 [email protected]

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

        // EMAIL SMTP SERVER INFORMATION
        oEmail.SmtpServer = "Server";
        oEmail.SetAuthentication("[email protected]", "Password");

        // EMAIL INFORMATION
        oEmail.From = "[email protected]";
        oEmail.To = "RecipientEmail";
        oEmail.Subject = this.txtMessage.Text;
        oEmail.Message = strMessage;

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

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

you have to set username in the SMTP Authentication as [email protected].

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

        // EMAIL SMTP SERVER INFORMATION
        oEmail.SmtpServer = "Server";
        oEmail.SetAuthentication("[email protected]", "Password");

        // EMAIL INFORMATION
        oEmail.From = "[email protected]";
        oEmail.To = "RecipientEmail";
        oEmail.Subject = this.txtMessage.Text;
        oEmail.Message = strMessage;

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

Your SMTP Server doesn't allow you to set Credential username different from oEmail.From (e-mail address of Sender).

南城追梦 2024-12-04 09:35:12

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

示例邮件代码:

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

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                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());
            }
}

Add Network credentials to your code.

Sample Mail Code:

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

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                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());
            }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文