asp.net发送邮件问题
谁有asp.net2.0发送邮件的代码,简单的就可以了
马上要,在线等,拿到就给分!
谢谢了。
------解决方案-------------------- public class SendMail
{
//----------------------发送一封邮件到用户的邮箱------------------------------
/// <summary>
/// 发送一封邮件到用户邮箱
/// </summary>
/// <param name= "toUser "> 收件地址 </param>
/// <param name= "fromUser "> 发件地址 </param>
/// <param name= "subject "> 主题 </param>
/// <param name= "content "> 内容 </param>
/// <param name= "mailFormat "> 邮件格式 </param>
/// <returns> </returns>
public SendMail(string toUser, string fromUser, string subject, string content, string mailFormat)
{
MailMessage mail = new MailMessage();//实像化MAIL对像
mail.To = toUser;//接收者
mail.From = fromUser;//发送者
mail.Subject = subject;//主题
mail.Body = content;//内容
mail.BodyEncoding = Encoding.GetEncoding( "GB2312 ");//编码
if(mailFormat.ToUpper() == "HTML ")
{
mail.BodyFormat = MailFormat.Html;
}
else
{
mail.BodyFormat = MailFormat.Text;
}
//smtp服务器
SmtpMail.SmtpServer = "smtp.163.com ";
mail.Fields[ "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate "] = "1 ";
//帐号
mail.Fields[ "http://schemas.microsoft.com/cdo/configuration/sendusername "]= "****@163.com ";
//密码
mail.Fields[ "http://schemas.microsoft.com/cdo/configuration/sendpassword "]= "**** ";
try
{
SmtpMail.Send(mail);
}
catch
{
}
}
}
------解决方案--------------------哈哈,我来坐沙发,今天来得早!
private bool SendEmail(string findpass,string toemail)
{
bool flag = false;
fromAddress = new MailAddress( "邮件地址 ", "发送着称呼 ", Encoding.GetEncoding( "gb2312 "));
toAddress = new MailAddress(toemail);
objMessage = new MailMessage(fromAddress, toAddress);
SmtpClient smtpClent = new SmtpClient( "服务器地址 ");
System.Net.NetworkCredential network = new System.Net.NetworkCredential( "邮件帐号 ", "密码 ");
objMessage.Subject = "找回密码 ";
objMessage.Body = "***提醒您,请及时修改自己的密码,您的密码是: " + findpass + " 请牢记您的密码! ";
//添加附件
//System.Net.Mail.Attachment mailfj = new System.Net.Mail.Attachment(File1.PostedFile.FileName);
//objMessage.Attachments.Add(mailfj);
objMessage.BodyEncoding = Encoding.GetEncoding( "gb2312 ");
objMessage.SubjectEncoding = Encoding.GetEncoding( "gb2312 ");
smtpClent.Credentials = network;
try
{
smtpClent.Send(objMessage);
lbMessage.Text = "发送成功,请检查您的邮箱及时修改密码! ";
flag = true;
}
catch (Exception)
{
lbMessage.Text = "发送失败 ";
//throw ex;
}
return flag;
}