var server = "yourmailserver";
string to = "s.fer@rm.com.tw";
string from = "rm@rm.com.tw";
var message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an email message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send email on the client's behalf.
client.Credentials = new System.Net.NetworkCredential("youraccount", "yourpwd");
// client.Port = 465;
// 改成 587, 465 會噴 The operations timed out
client.Port = 587;
client.EnableSsl = true;
client.Send(message);
System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpserver",
"yourmailserver");
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpserverport",
"465");
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendusing",
"2");
//sendusing: cdoSendUsingPort, value 2, for sending the message using
//the network.
//smtpauthenticate: Specifies the mechanism used when authenticating
//to an SMTP
//service over the network. Possible values are:
//- cdoAnonymous, value 0. Do not authenticate.
//- cdoBasic, value 1. Use basic clear-text authentication.
//When using this option you have to provide the user name and password
//through the sendusername and sendpassword fields.
//- cdoNTLM, value 2. The current process security context is used to
// authenticate with the service.
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//Use 0 for anonymous
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendusername",
"username");
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"userpwd");
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
"true");
myMail.From = "rm@rm.com.tw"
myMail.To = "s.fer@rm.com.tw";
myMail.Subject = "test sub";
myMail.BodyFormat = MailFormat.Html;
myMail.Body = "body";
System.Web.Mail.SmtpMail.SmtpServer = "yourmailserver:465";
System.Web.Mail.SmtpMail.Send(myMail);