|
This text only shows how to send e-mails in asp.net 2.0, including html emails. This article do not show how to send emails with attached files. This is a subject for another article. Follow the steps described below. 1- First, put this configuration int the web.config file in the web application root folder: ... </system.web> ... <system.net> <mailSettings> <smtp from="
This email address is being protected from spam bots, you need Javascript enabled to view it
"> <network host="192.168.0.6" port="25" password="pass" userName="userx" /> </smtp> </mailSettings> </system.net> ...
The following code can be used to send emails. You must replace the '...' by the appropriated 'using xxx' lines if necessary. ... using System.Net.Mail; ... ... SmtpClient client = new SmtpClient(); MailAddress from = new MailAddress("
This email address is being protected from spam bots, you need Javascript enabled to view it
", "namefrom"); MailAddress to = new MailAddress("
This email address is being protected from spam bots, you need Javascript enabled to view it
", "nameto"); MailMessage message = new MailMessage(from, to); message.IsBodyHtml = true; message.Subject = "Your friend xxx blablabla.."; string fullText = "this is the full mail text.... lalalla..."; message.Body = fullText; try { client.Send(message); Response.Redirect("somepage.aspx"); } catch (Exception ex) { //using some log component, you can remove this lines if you want log.Error("Error sending email"); log.Error(ex); } That's it! easy and simple! In the try block, the redirect was only used to send the user to the success page. |