Asp.Net Mail Sending

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Net.Mime;

public partial class _Default : System.Web.UI.Page
{

protected void btnSend_Click(object sender, EventArgs e)
{    
    MailMessage msg = new MailMessage();
        msg.From = new MailAddress(Mail Address From);
        msg.To.Add("EmailId1,EmailId2");
        msg.Subject = "Ankit N. Pansuriya";
        msg.IsBodyHtml = true;
        msg.Body = txtMsgBody.Text.ToString();
        Attachment at = new Attachment(Server.MapPath("~/Upload/" + FileUpload1.FileName.ToString()));
        msg.Attachments.Add(at);
        msg.Priority = MailPriority.High;
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("your id", "password");
        client.EnableSsl = true;
        object userstate = msg;
        client.Send(msg);
}

}
Ebook Download
View all
Learn
View all