在System.Net.Mail中发送电子邮件
问题描述:
大家好.
我的服务器管理员告诉我,将发送电子邮件的身份验证方法设置为true.
你能告诉我该怎么办?电子邮件的身份验证方法是什么?
这是我的代码和用于发送电子邮件的web.config:
Hi every one.
My server administrator told me that set true your authenticatio method for sending email.
can u tell me what can i do? and what is Authentication method for Email ?
Here is my code and my web.config for sending emails :
<system.net>
<mailSettings>
<smtp from="info@amicoyasnapars.com">
<network host="mail.amicoyasnapars.com" port="25" userName="info@amicoyasnapars.com" password="mypassword" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>
发送后的C#代码:
C# Code Behind for sending :
public bool SendContact(string FullName, string UserEmail, string Comment, int Lang, string Phone)
{
try
{
CTable = CompClass.Get_2142Items(Lang);
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
//From Customer To Us!
message.To.Add("info@amicoyasnapars.com");
//message.From = MailFAddress;
message.Subject = "New Contact From Site";
message.IsBodyHtml = true;
//888888888888888888888888888888888888888888888888888888
message.Body = "<font face='Tahoma' size='2'><strong>نام کامل : </strong></font>" + FullName + "<br>";
message.Body += "<font face='Tahoma' size='2'><strong>ایمیل : </strong></font>" + UserEmail + "<br>";
message.Body += "<font face='Tahoma' size='2'><strong>تلفن : </strong></font>" + Phone + "<br>";
message.Body += "<font face='Tahoma' size='2'><strong>پیام : </strong></font>" + Comment + "<br>";
//888888888888888888888888888888888888888888888888888888
message.BodyEncoding = System.Text.Encoding.UTF8;
smtp.Send(message);
return true;
}
catch (Exception ex)
{
return false;
}
}
谢谢大家.
Thank u all.
答
这里有完整的通用电子邮件发送例程: ^ ]
There is a complete Generic routine for Email sending here: Sending an Email in C# with or without attachments: generic routine.[^]