I have created one webpage in ASP.net with C#. In which I have put one button when this button clicks need to send mail. But, when I click on this button getting this exception :- System.Net.Mail.SmtpException: Transaction failed. The server response was: 5.7.1 : Relay access denied at System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.Button1_Click(Object sender, EventArgs e) in c:\Users\jay.desai\Documents\Visual Studio 2013\WebSites\WebSite2\Default.aspx.cs:line 47
我用ASP#在ASP.net中创建了一个网页。我点击这个按钮时需要发一个按钮才能发送邮件。但是,当我点击此按钮获取此异常时: - System.Net.Mail.SmtpException:事务失败。服务器响应是:5.7.1:在System.Net.Mail.SmtpTransport.SendMail的System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode statusCode,String响应)中拒绝中继访问(MailAddress发送者,MailAddressCollection收件人,String deliverNotify,布尔值在System.Net.Mail.SmtpClient.Send(MailMessage消息)的System.Net.Mail.SmtpClient.Send(MailMessage消息)中的allowUnicode,SmtpFailedRecipientException&exception)在c:\ Users \ jay.desai \ Documents \ Visual Studio 2013 \ WebSites \ WebSite2中的_Default.Button1_Click(Object sender,EventArgs e) Default.aspx.cs:第47行
Please refer below code:-
请参考以下代码: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("serveradmin.dmd@ril.com");
mail.Subject = "Pallet Shortage Emergency";
mail.To.Add("jay.desai@ril.com");
mail.Body ="Only 100 pallets are availabe in ASRS. This is system generated mail do not reply";
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpClient smtp = new SmtpClient("rmta010.zmail.ril.com",25);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential("serveradmin.dmd@ril.com", "1234");
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
1 个解决方案
#1
0
The server error is indicating that it will not relay messages. Usually this means that you need to authenticate with the server before it will allow you to send email, or that it will only accept emails for delivery from specific source domains.
服务器错误表明它不会中继消息。通常这意味着您需要先对服务器进行身份验证,然后才能发送电子邮件,或者只接受来自特定源域的电子邮件。
If you are always going to be sending to a single email domain then you can generally use the registered MX server for the domain. In this case (ril.com) the MX server list includes several primary mail servers, but the first one for me is: gwhydsmtp010.ril.com. I'd try that as the target mail server if your website is hosted outside the network that the mail server is on.
如果您总是要发送到单个电子邮件域,那么您通常可以使用已注册的MX服务器作为域。在这种情况下(ril.com),MX服务器列表包括几个主要邮件服务器,但第一个对我来说是:gwhydsmtp010.ril.com。如果您的网站托管在邮件服务器所在的网络之外,我会尝试将其作为目标邮件服务器。
Alternatively you can provide SMTP login credentials to the SmtpClient
object like this:
或者,您可以向SmtpClient对象提供SMTP登录凭据,如下所示:
SmtpClient smtp = new SmtpClient("rmta010.zmail.ril.com",25);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "password");
Logging in to the server will generally solve most 5.7.1 errors.
登录到服务器通常可以解决大多数5.7.1错误。
One final method that might be useful if you have admin rights on the Exchange server is to setup an SMTP connector to allow relay from a specific source address (your web server). I wouldn't recommend this however as any open relay is a Bad Idea(tm).
如果您在Exchange服务器上拥有管理员权限,则可能有用的最后一种方法是设置SMTP连接器以允许从特定源地址(您的Web服务器)进行中继。我不建议这样做,因为任何开放式接力都是坏主意(tm)。
#1
0
The server error is indicating that it will not relay messages. Usually this means that you need to authenticate with the server before it will allow you to send email, or that it will only accept emails for delivery from specific source domains.
服务器错误表明它不会中继消息。通常这意味着您需要先对服务器进行身份验证,然后才能发送电子邮件,或者只接受来自特定源域的电子邮件。
If you are always going to be sending to a single email domain then you can generally use the registered MX server for the domain. In this case (ril.com) the MX server list includes several primary mail servers, but the first one for me is: gwhydsmtp010.ril.com. I'd try that as the target mail server if your website is hosted outside the network that the mail server is on.
如果您总是要发送到单个电子邮件域,那么您通常可以使用已注册的MX服务器作为域。在这种情况下(ril.com),MX服务器列表包括几个主要邮件服务器,但第一个对我来说是:gwhydsmtp010.ril.com。如果您的网站托管在邮件服务器所在的网络之外,我会尝试将其作为目标邮件服务器。
Alternatively you can provide SMTP login credentials to the SmtpClient
object like this:
或者,您可以向SmtpClient对象提供SMTP登录凭据,如下所示:
SmtpClient smtp = new SmtpClient("rmta010.zmail.ril.com",25);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "password");
Logging in to the server will generally solve most 5.7.1 errors.
登录到服务器通常可以解决大多数5.7.1错误。
One final method that might be useful if you have admin rights on the Exchange server is to setup an SMTP connector to allow relay from a specific source address (your web server). I wouldn't recommend this however as any open relay is a Bad Idea(tm).
如果您在Exchange服务器上拥有管理员权限,则可能有用的最后一种方法是设置SMTP连接器以允许从特定源地址(您的Web服务器)进行中继。我不建议这样做,因为任何开放式接力都是坏主意(tm)。