
Step 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//===============================================//
MailMessage mail = new MailMessage();
mail.To.Add(TextBox_email.Text);
mail.From = new MailAddress("[email protected]");
mail.Subject = TextBox_sub.Text;
mail.Body = TextBox_body.Text;
mail.IsBodyHtml = true;
Attachment file = new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName);
mail.Attachments.Add(file);
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("youremail", "yourpassword");
smtp.Send(mail);
Label6.Text = "Email to " + TextBox_email.Text + " has been send successfully";
//======================================================//
}
catch(Exception ex)
{
Label6.Text = ex.Message;
}
}
}
MailMessage mail = new MailMessage();
mail.To.Add(TextBox_email.Text);
mail.From = new MailAddress("sender's email");
mail.Subject = TextBox_sub.Text;
mail.Body = TextBox_body.Text;
mail.IsBodyHtml = true;
Attachment file = new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName);
mail.Attachments.Add(file);
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("sender's email", "sender's password");
smtp.Send(mail);
Label6.Text = "Email to " + TextBox_email.Text + " has been send successfully";


Join the conversation! Your thoughts help the community grow.