| Author: VijayKumar Reddy M 25 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
Namespaces Used
using System.Net.Mail; using System.Net.Mime;
CODE
// send mail to the new user who has registered. protected void yourButton_Click(object sender, EventArgs e) { string strMailContent = "Welcome new user"; string fromAddress = "yourname@yoursite.com"; string toAddress = "newuser@hisdomain.com"; string contentId = "image1"; string path = Server.MapPath(@"images/Logo.jpg"); // my logo is placed in images folder MailMessage mailMessage = new MailMessage( fromAddress, toAddress ); mailMessage.Bcc.Add("inkrajesh@hotmail.com"); // put your id here mailMessage.Subject = "Welcome new User";
LinkedResource logo = new LinkedResource(path); logo.ContentId = "companylogo"; // done HTML formatting in the next line to display my logo AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:companylogo/><br></body></html>" + strMailContent, null, MediaTypeNames.Text.Html); av1.LinkedResources.Add(logo);
mailMessage.AlternateViews.Add(av1); mailMessage.IsBodyHtml = true; SmtpClient mailSender = new SmtpClient("localhost"); //use this if you are in the development server mailSender.Send(mailMessage); }
Note:SmtpClient mailSender = new SmtpClient(ConfigurationManager.AppSettings["MyCustomId"]); // use this in the Production Server. I have specified my email server in the web.config file
|