我用C#在ASP.net中創建了一個網頁。當這個按鈕點擊需要發送郵件時,我已經放了一個按鈕。但是,當我點擊這個按鈕得到這個例外: - System.Net.Mail.SmtpException:事務失敗。服務器響應是:5.7.1:中繼訪問在System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode statusCode,String response)上被拒絕System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,MailAddressCollection recipients,String deliveryNotify,Boolean在System.Net.Mail.SmtpClient.Send(MailMessage消息)位於c:\ Users \ jay.desai \ Documents \ Visual Studio 2013 \ WebSites \ WebSite2中的_Default.Button1_Click(對象發件人,EventArgs e)處,允許使用Unicode,SmtpFailedRecipientException &異常) \ Default.aspx.cs:行47無法使用C#使用ASP.net從SMTP服務器發送郵件#
請參考下面的代碼: -
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("[email protected]");
mail.Subject = "Pallet Shortage Emergency";
mail.To.Add("[email protected]");
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("[email protected]", "1234");
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
嘗試使用管理員權限運行您的程序。 –
@MaximGoncharuk同樣的問題 –
看看這個[link](http://forums.asp.net/t/1908812.aspx?Relay+access+denied+at+System+Net+Mail+RecipientCommand+CheckResponse+only+with +一些+電子郵件) –