.NET 2.0否决了原来的System.Web.Mail,而启用新的命名空间System.Net.Mail。注意要实现SMTP时,别忘了using System.Net;和using System.Net.Mail;
下面看SMTP的核心代码
public
bool
SendEmail(
string
strServerAddress,
string
strServerPort,
string
strServerUID,
string
strServerPWD,
string
strSenderEmail,
string
strReceiverEmail,
string
strSubject,
string
strBody,
string
strAttachment)
{
try
{
SmtpClient smtp = new SmtpClient(strServerAddress, int .Parse(strServerPort));
smtp.Credentials = new NetworkCredential(strServerUID, strServerPWD);
MailMessage mail = new MailMessage(strSenderEmail, strReceiverEmail, strSubject, strBody);
if (strAttachment != string .Empty)
{
Attachment file = new Attachment(strAttachment);
mail.Attachments.Add(file);
}
smtp.Send(mail);
return true ;
}
catch
{
return false ;
}
}
{
try
{
SmtpClient smtp = new SmtpClient(strServerAddress, int .Parse(strServerPort));
smtp.Credentials = new NetworkCredential(strServerUID, strServerPWD);
MailMessage mail = new MailMessage(strSenderEmail, strReceiverEmail, strSubject, strBody);
if (strAttachment != string .Empty)
{
Attachment file = new Attachment(strAttachment);
mail.Attachments.Add(file);
}
smtp.Send(mail);
return true ;
}
catch
{
return false ;
}
}