Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Sending email in ASP.net

Sending email in ASP.net

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rehal
    wrote on last edited by
    #1

    Hi Please tell me how can we send email from an ASP.net application to a yahoo or gmail account? Thanks

    N C 2 Replies Last reply
    0
    • R rehal

      Hi Please tell me how can we send email from an ASP.net application to a yahoo or gmail account? Thanks

      N Offline
      N Offline
      netsooz Amir Hamidi
      wrote on last edited by
      #2

      to send an email from your application you have to ways: 1- use smtp server of your own 2- use one of the free smtp servers like gmail's accordingly after choosing your smtp there are two coding ways that goes as below: 1- add namespace of System.Net.mail; 2-in the click event of your [Send Email] button:

      MailMessage mailmsg= new MailMessage();
      mailmsg.From = new MailAddress("Your Email Address");
      mailmsg.To.Add("Email of reciver");
      mailmsg.Subject = "Your sybject";
      mailmsg.Body = "The body of your mail (You can use html tags too";
      mailmsg.IsBodyHtml = true;
      SmtpClient smpt= new SmtpClient("127.0.0.1"); [if you are using your application in your own host]
      smtp.Send(mailmsg);

      ----------------------- Now if you don't have your own smtp and wanna use free one like google's do as below: 1- add the same name space 2- Code as below:

      string subject = "Your Subject";
      string from = "Your Gmail account having @gmail.com";
      string rec = "reciver email";
      string body = "The mail body.";
      MailMessage mail = new MailMessage(from, rec);
      mail.IsBodyHtml = true;
      mail.SubjectEncoding = System.Text.UnicodeEncoding.UTF8;
      mail.Subject = subject;
      mail.Body = body;
      SmtpClient sm = new SmtpClient();
      System.Net.NetworkCredential me = new System.Net.NetworkCredential();
      me.UserName = "your gmail username";
      me.Password = "your gmail password";
      sm.UseDefaultCredentials = false;
      sm.Credentials = me;
      sm.Host = "smtp.gmail.com";
      sm.Port = 587;
      sm.EnableSsl = true;
      sm.Send(mail);

      hope it works

      Proper Prepration Prevents Poor Performance! h

      1 Reply Last reply
      0
      • R rehal

        Hi Please tell me how can we send email from an ASP.net application to a yahoo or gmail account? Thanks

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I wrote an article on how to use google. Because sending an email is 1 - trivial 2 - widely documented 3 - asked here often I based my tutorial on how to use google to search for how to send an email. Really 'send email C#' is all you needed, but I suggest you read the article anyhow.

        Christian Graus Driven to the arms of OSX by Vista.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups