Email using ASP.NET

Discussion in 'ASP.NET' started by jazzlearner, Nov 14, 2008.

  1. jazzlearner

    jazzlearner New Member

    Joined:
    Nov 13, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    HI ALL,
    Can any one tell me,How to send an email using ASP.NET? How to use system.web.mail.I will highly appereciate your feedback.

    Thanks in advance!
    Jazz
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  3. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    http://www.ifourtechnolab.com/
    Hi,

    You can check this

    Code:
    using System.IO;
    using System.Net;
    using System.Net.Mail;
    protected void SendEmail(object sender, EventArgs e)
    {
    using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
      {
      mm.Subject = txtSubject.Text;
      mm.Body = txtBody.Text;
    if (fuAttachment.HasFile)
      {
    string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
      mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
      }
      mm.IsBodyHtml = false;
    SmtpClient smtp = new SmtpClient();
      smtp.Host = "smtp.gmail.com";
      smtp.EnableSsl = true;
    NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
      smtp.UseDefaultCredentials = true;
      smtp.Credentials = NetworkCred;
      smtp.Port = 587;
      smtp.Send(mm);
      ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
      }
    }
    Thanks
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice