using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Data;
using System.Web.Mail;
using System.Net;
using System.Net.Mail;
using System.IO;
using System.Drawing;
using System.Xml;
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
System.Net.Mail.MailMessage obj = new System.Net.Mail.MailMessage();
SmtpClient serverobj = new SmtpClient();
serverobj.Credentials = new NetworkCredential("anilmeets4u@gmail.com", "########");
serverobj.Port = 587;
serverobj.Host = "smtp.gmail.com";
serverobj.EnableSsl = false;
obj = new System.Net.Mail.MailMessage();
obj.From = new MailAddress("anilmeets4u@gmail.com", "AgileLearning.com", System.Text.Encoding.UTF8);
obj.To.Add(ASPxtxtToUser.Text);
obj.CC.Add(txtCcUser.Text);
obj.Priority = System.Net.Mail.MailPriority.High;
obj.Subject = txtSubject.Text;
string date = DateTime.Now.ToString();
obj.Body = ASPxMemo1.Text;
HttpFileCollection hfc = Request.Files;
for (int z = 0; z < hfc.Count; z++)
{
HttpPostedFile hpf = hfc[z];
if (hpf.ContentLength > 0)
{
uploadfile.SaveAs(Server.MapPath("MailFiles") + "\\" + Path.GetFileName(hpf.FileName));
string FileName = Server.MapPath("MailFiles") + "\\" + Path.GetFileName(hpf.FileName);
obj.Attachments.Add(new Attachment(FileName));
obj.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
serverobj.Send(obj);
Page.RegisterClientScriptBlock("pageClose", "<script>alert('Your Request Send Sucessfully');</script>");
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
Try this it will work