Net2.0 requires service period verification. The Code is as follows:
Needless to say
Public class mail
{
Private string subject;
Private string [] mailto;
Private string body;
Private string smtpserver;
Private string user;
Private string password;
Private string sender;
Public mail (string subject, string [] mailto, string sender, string body, string SMTP, string user, string pass)
{
This. Subject = subject;
This. mailto = mailto;
This. Body = body;
This. smtpserver = SMTP;
This. User = user;
This. Password = pass;
This. Sender = sender;
}
Public bool send ()
{
Bool flag = true;
Try
{
System. net. Mail. mailmessage mailobj = new system. net. Mail. mailmessage ();
// Add mailto address
For (INT I = 0; I <mailto. length; I ++)
{
Mailobj. to. Add (mailto [I]);
}
Mailobj. isbodyhtml = true;
Mailobj. Subject = subject;
String from = user + "@" + smtpserver. substring (smtpserver. indexof (".") + 1, smtpserver. Length-smtpserver. indexof (".")-1 );
Mailobj. From = new mailaddress (from, sender, system. Text. encoding. utf8 );
Mailobj. Body = body;
System. net. Mail. smtpclient smtpmail = new smtpclient (smtpserver );
Smtpmail. Credentials = new system. net. networkcredential (from, password );
Smtpmail. Send (mailobj );
Flag = true;
}
Catch
{
Flag = false;
}
Return flag;
}
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/mengyao/archive/2007/08/29/1764256.aspx