//原来以为微软提供的发送电子邮件的组件太简单,根本不能发送邮件。看了很多书上的例子,都没有提到认证怎么配。后来看到一篇文章,终于学到这一点。在自己的机器上测试成功,采用smtp.163.com的服务器
MailMessage mail = new MailMessage();
mail.To = “me@mycompany.com”;
mail.From = “you@yourcompany.com”;
mail.Subject = “this is a test email.”;
mail.Body = “Some text goes here”;
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”, “1”); //basic authentication
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendusername”, “my_username_here”); //set your username here
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendpassword”, “super_secret”); //set your password here
SmtpMail.SmtpServer = “mail.mycompany.com”; //your real server goes here
SmtpMail.Send( mail );
如非注明转载, 均为原创. 本站遵循知识共享CC协议,转载请注明来源