Monday 6 July 2015

Send Mail with Attachment Files Using Asp.net

using System.Net.Mail;

SmtpClient client = new SmtpClient();
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            client.Timeout = 10000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "Password");

            MailMessage mm = new MailMessage();
            mm.Subject = "Sending Mail Using Asp.net";
            mm.Body = "Hi, \n\n\Mail Sent Successfully \n\n\n --\n -- \nBest Regards\n"
                + "\n\n-----------------------------------------------------------------------\nThis is a system-generated e-mail, please don't reply to this message.";
            mm.Attachments.Add(new Attachment(File));
            mm.From = new MailAddress("xyz@gmail.com");
            mm.To.Add("xyz@gmail.com");             
            mm.CC.Add("xyz@gmail.com");
            client.Send(mm);

No comments:

Post a Comment