Thursday, 28 March 2013

Send Email with attachment In Asp .Net with c#

Send Email with attachment In Asp .Net with c#       

 string filePath  ="C:\\abc.doc";
        string senderEmailid="senderemailid@gmail.com";
        string senderPassword="password";
        string recieverEmailid="recievermailid@gmail.com";
        var client = new SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new NetworkCredential(senderEmailid, senderPassword),
            EnableSsl = true
        };

        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(senderEmailid,             recieverEmailid);

        mail.Attachments.Add(new Attachment(Server.MapPath(filePath)));

        mail.Subject ="Subject of Mail"
        mail.Body ="<b>Hai</b>";
   
       
        mail.IsBodyHtml = true; // To make html

        client.Send(mail);

2 comments:

  1. I read this article,Asp.net provides a email service to send mail easily.thanks for sharing valuable post.

    ReplyDelete

IE7 Issues Text Indent

                 Unfortunately IE 7 is still widespread among the users hence while theming we have to give special importance to the grea...