none
Email in .NET RRS feed

  • Question

  • How to send email from a asp.net webpage.

    what to write on the click event of the send button?

    Please help....

    Monday, December 5, 2011 2:42 PM

Answers

  • This is all covered in MSDN so it doesn't need to be repeated here.  Refer to System.Mail.MailMessage.  It provides a complete example.

    Michael Taylor - 12/5/2011
    http://msmvps.com/blogs/p3net

    Monday, December 5, 2011 2:46 PM
    Moderator
  • if you want to send a email in your c# code. try this:

     

                                string htmlEmailMessage = ### HTML MESSAGE ###;
                                emailMessage = ### PLAIN TEXT MESSAGE ###;
                                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlEmailMessage, Encoding.UTF8, "text/html");                             using (MailMessage msg = new MailMessage(EMailNotification.EMailAddress, recipient.EMail, "Subject", emailMessage))                             {                                 // HTML-Teil der Email hinzufügen:                                 msg.AlternateViews.Add(htmlView);                                 using (SmtpClient client = new SmtpClient(EMailNotification.EMailServer) { EnableSsl = true })                                 {                                     var credentials = new System.Net.NetworkCredential(EMailNotification.Username, EMailNotification.Password);                                     client.Credentials = credentials;                                     client.Send(msg);                                 }                             }

     

    Monday, December 5, 2011 2:49 PM
  • As an aside, if the target is Exchange Server 2007 SP1 or greater one should use Exchange Web Services which would allow C# code to send/read emails from a specific email account without having to even install Office! I blog about it here:

    C#: Getting All Emails From Exchange using Exchange Web Services
    Tribal Knowledge: EWS C# Extract Alternate Email Address’ Mailbox

    See

    Exchange Web Services Managed API (install & read doc on how to access EWS)
    EWS Editor (demonstrates all EWS operations)
    EWS Forum top level post for all Exhange information / links
    Exchange Development Forum for more information


    William Wegerson (www.OmegaCoder.Com)
    Monday, December 5, 2011 2:58 PM
    Moderator

All replies

  • This is all covered in MSDN so it doesn't need to be repeated here.  Refer to System.Mail.MailMessage.  It provides a complete example.

    Michael Taylor - 12/5/2011
    http://msmvps.com/blogs/p3net

    Monday, December 5, 2011 2:46 PM
    Moderator
  • if you want to send a email in your c# code. try this:

     

                                string htmlEmailMessage = ### HTML MESSAGE ###;
                                emailMessage = ### PLAIN TEXT MESSAGE ###;
                                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlEmailMessage, Encoding.UTF8, "text/html");                             using (MailMessage msg = new MailMessage(EMailNotification.EMailAddress, recipient.EMail, "Subject", emailMessage))                             {                                 // HTML-Teil der Email hinzufügen:                                 msg.AlternateViews.Add(htmlView);                                 using (SmtpClient client = new SmtpClient(EMailNotification.EMailServer) { EnableSsl = true })                                 {                                     var credentials = new System.Net.NetworkCredential(EMailNotification.Username, EMailNotification.Password);                                     client.Credentials = credentials;                                     client.Send(msg);                                 }                             }

     

    Monday, December 5, 2011 2:49 PM
  • As an aside, if the target is Exchange Server 2007 SP1 or greater one should use Exchange Web Services which would allow C# code to send/read emails from a specific email account without having to even install Office! I blog about it here:

    C#: Getting All Emails From Exchange using Exchange Web Services
    Tribal Knowledge: EWS C# Extract Alternate Email Address’ Mailbox

    See

    Exchange Web Services Managed API (install & read doc on how to access EWS)
    EWS Editor (demonstrates all EWS operations)
    EWS Forum top level post for all Exhange information / links
    Exchange Development Forum for more information


    William Wegerson (www.OmegaCoder.Com)
    Monday, December 5, 2011 2:58 PM
    Moderator