How to send mail with attachment through coding?

MailMessage obj = new MailMessage();
obj.From = new MailAddress(“admin@asd.com”);
obj.To.Add(“gaur1982@yahoo.com”);
obj.Subject = “Only 4 testing”;
obj.IsBodyHtml = true;
obj.Body = message.ToString();
Attachment atch=new Attachment(Server.MapPath(“~/Attach/123.txt”));
obj.Attachment.Add(atch);
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(obj);

Tagged . Bookmark the permalink.

Leave a Reply