using System; using System.Collections; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; using System.Web.Services; using System.Globalization; using System.Net.Mail; using System.Net.Mime; using System.Net; public partial class SendMail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Send(object sender, EventArgs e) { string subject = "CNet"; string body = ""; string from = "from"; string password = "pwd"; string server = "mail.npgnet.ir"; string to = "r.ghafari@npg.ir"; try { MailMessage mail = new MailMessage(); mail.To.Add(to); mail.From = new MailAddress(from, subject); mail.Subject = "Test with Image"; string Body = "Welcome to codedigest.com!!<br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >"; AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html"); LinkedResource imagelink = new LinkedResource(Server.MapPath(".") + @"\pic.gif", "image/gif"); imagelink.ContentId = "imageId"; imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64; htmlView.LinkedResources.Add(imagelink); mail.AlternateViews.Add(htmlView); SmtpClient smtp = new SmtpClient(); smtp.Port = 25; smtp.Host = server; smtp.Credentials = new NetworkCredential(from, password); //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; smtp.Send(mail); } catch (Exception ex) { Response.Write(ex.Message); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)