// 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)
答案 0 :(得分:2)
5.7.1 ==转发被禁止的
您需要允许中断已通过身份验证的用户,或来自SMTP服务器的一系列IP:http://support.microsoft.com/kb/304897
您使用什么类型的服务器来传递消息?
答案 1 :(得分:1)
您必须在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(发件人的电子邮件地址)不同的凭据用户名。
答案 2 :(得分:0)
将网络凭据添加到您的代码中。
示例邮件代码:
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());
}
}