我也想要啊
这是我写的一个发邮件方法,可以参考一下:
public void SendMail(string MessageFrom,string name,string password,string MessageTo,string MessageSubject,string MessageBody,string MailServer,string fileName)
{
SmtpMail.SmtpServer =MailServer;
MailMessage oMessage = new MailMessage();
oMessage.BodyFormat = MailFormat.Html;
oMessage.Priority = MailPriority.Normal;
oMessage.From = MessageFrom;
oMessage.To = MessageTo;
oMessage.Subject = MessageSubject;
//Stmp authentication
oMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
oMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", name);
oMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",password);
oMessage.Body = MessageBody;
MailAttachment oAttachment=null;
if(File.Exists(fileName))
{
oAttachment = new MailAttachment(fileName);
oMessage.Attachments.Add(oAttachment);
}
try
{
System.Console.WriteLine("Sending outgoing message......");
SmtpMail.Send(oMessage);
}
catch( System.Web.HttpException exHttp )
{
System.Console.WriteLine("Exception occurred: " +
exHttp.Message);
}
}
现在微软提倡用 System.Net.Mail类
System.Web.Mail类已经不建议用了,
还有smtpMail类
改成SmtpClient了,并且用法也变了点!