UsingthenewASP.NETv2.0SMTPClass

UsingthenewASP.NETv2.0SMTPClass


Due to the fact that System.Web.Mail.SmtpMail is obsolete now, here's a little Snippet for you which shows the use of the replacement class. You can leave out the SMTPServer stuff if you're Mailserver runs locally and doesn't require local authentication.


using System.Net.Mail;

  ...

  protected void Button1_Click(object sender, EventArgs e)
    {
        string SMTPServer = "mail.sunlab.de";
        string fromAddress = "Andreas.Kraus@sunlab.de";
        string fromName = "Andreas Kraus";
        string toAddress = "info@kmc-home.com";
        string toName = "KMC Studios";
        string msgSubject = "Meeting";
        string msgBody = "Today";       
     
        SmtpClient client = new SmtpClient(SMTPServer);
        client.Credentials= new System.Net.NetworkCredential("Andreas.Kraus@sunlab.de", "thepw");
        MailAddress from = new MailAddress(fromAddress, fromName);
        MailAddress to = new MailAddress(toAddress, toName);
        MailMessage message = new MailMessage(from, to);
     
        message.Subject = msgSubject;
        message.Body = msgBody;
   
        client.Send(message);
    }

Andreas Kraus aka `reteep`

http://www.sunlab.de


  (2005-5-02:08:28)

 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 您可能对 [Visual Studio.NET] 的这些文章也感兴趣:

.NET精简版框架的Power Toys
Windows Workflow Foundation 之旅---(1)Hello,Workflow!
MS MVC框架漩涡中的MonoRail未来
.NET框架图解之八:ASP.NET
MonoRail和WebForm,谁是瑞士军刀
计划中的VS10特性将会作为VS2008的扩展而发布
BlogEngine.Net架构与源代码分析系列part7:Web2.0特性——Pingback&Trackba
创建自己的Visual Studio Item模板
使用SOAP头实现.NET程序访问JAVA的WebService
How to build Multi-Language Web Sites