Skip to content

Instantly share code, notes, and snippets.

@G-Sudarshan
Created February 7, 2020 06:16
Show Gist options
  • Select an option

  • Save G-Sudarshan/4e77923feb3270be06f7b464e57864c5 to your computer and use it in GitHub Desktop.

Select an option

Save G-Sudarshan/4e77923feb3270be06f7b464e57864c5 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net.Configuration;
using System.Net;
using System.Configuration;
using System.Text;
namespace email
{
public partial class WebForm1 : 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.From = new MailAddress(TextBox1.Text);
SmtpClient smtpobj = new SmtpClient("smtp.gmail.com");
smtpobj.Port = 25;
mail.SubjectEncoding = Encoding.UTF8;
mail.Priority = MailPriority.Normal;
smtpobj.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpobj.UseDefaultCredentials = false;
smtpobj.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
mail.Subject = TextBox3.Text;
smtpobj.EnableSsl = true;
smtpobj.Timeout = 40000;
mail.To.Add(TextBox2.Text);
if (FileUpload1.HasFile)
{
mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
smtpobj.Send(mail);
Label4.Text = "mail sent ";
mail.To.Clear();
}
catch (Exception ex)
{
Label4.Text = ex.StackTrace;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment