发送邮件
方法:
public static bool SendMail(string From,string To,string Subject,string Baby)
{
try
{
MailMessage msg = new MailMessage(From,To,Subject,Baby);
SmtpClient smtp = new SmtpClient( "localhost ");
smtp.Send(msg);
return true;
}
catch
{
return false;
}
}
调用:
Functions.SendMail( "Eseate.net ", "yufei1237@163.com ", "注册验证 ", "验证邮件 ");
第一次做,找人教教,最好能加好友
------解决方案--------------------很简单就这么几句
步骤1:using System.Net.Mail;
步骤2: #region 电子邮件发送新密码给用户
private void SendEmail()
{
try
{
MailMessage m_message = new MailMessage();
m_message.From = new MailAddress( "admin@xunku.cn ");
m_message.To.Add(new MailAddress( "hzl091@126.com "));
m_message.Subject = "hello ";
m_message.Body = "正在进行邮件发送测试, <font color= 'red '> <a href= 'http://www.xunku.cn '> 去讯酷看看 </a> </font> ";
SmtpClient m_smtpClient = new SmtpClient();
m_smtpClient.Send(m_message);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion 电子邮件发送新密码给用户
步骤3:配置web.config(可以利用网站管理工具来配置)
<system.net>
<mailSettings>
<smtp from= "admin@xunku.cn ">
<network host= "mail.xunku.cn " password= "******** " userName= "admin@xunku.cn " />
</smtp>
</mailSettings>
</system.net>
注意:特别要说明的是有些免费邮箱是不支持SMTP协议的,所以如果你用下面的配置发送邮件将会失败
<system.net>
<mailSettings>
<smtp from= "hzl091@163.com ">
<network host= "mail.163.com " password= "******** " userName= "hzl091@163.com " />
</smtp>
</mailSettings>
</system.net>
所以一定要找一个支持SMTP的邮件服务器才行
------解决方案--------------------我用的函数:
public static void SendMail(string strSmtpServer, string strForm, string strFormPass, string strto, string strSubject, string strBody)
{
System.Net.Mail.SmtpClient clint = new SmtpClient(strSmtpServer);
clint.UseDefaultCredentials = false;
clint.Credentials = new