ASP.NET- Sending an e-mail

asp.net

I am doing a Flight booking system and I want to send an E-Mail to the user which wiil contain the E-Ticket of his travel. The E-Ticket is generated dynamically with the booking ID fetched from the database and the other details from the previous pages like Name of the passenger and all. So how can I send him the dynamically generated E-Ticket to his E-Mail ID?

Best Answer

WARNING: My original answer to this question suggest using System.Web.Mail for sending e-mails. However, this API has been replaced by System.Net.Mail back in .NET 2.0, and the classes of System.Web.Mail are now all marked obsolete/deprecated.


You can use the System.Web.Mail.Mailmessage class:

System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
mailMessage.To = "recipient@repipient.com";
mailMessage.From = "sender@sender.com";
mailMessage.Subject = "Email subject";
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Html;
mailMessage.Body = "Email body";

System.Web.Mail.SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["mailserver"];
System.Web.Mail.SmtpMail.Send(mailMessage);
Related Topic