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. General Programming
  3. C#
  4. Sending Mail in C#

Sending Mail in C#

Scheduled Pinned Locked Moved C#
csharpsysadminsecuritytutorial
6 Posts 4 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.
  • S Offline
    S Offline
    Sassan Komeili Zadeh
    wrote on last edited by
    #1

    Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh

    V L J 3 Replies Last reply
    0
    • S Sassan Komeili Zadeh

      Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Hmm... There have been umpteen articles on this topic in C#.

      MailMessage msg = new MailMessage();
      msg.From = "crawler@deepak.portland.co.uk";
      msg.To = "crawler@deepak.portland.co.uk";
      msg.Subject = "Test";
      msg.Body = "Hi! Hello" +"\nSent Via MailMessage and SmtpMail Class";
      SmtpMail.SmtpServer = "smtp.yourmailserver.yourisp.com";
      SmtpMail.Send(msg);
      SmtpMail.Send("crawler@deepak.portland.co.uk","crawler@deepak.portland.co.uk","Test","Hi! Hello\nSent Via SmtpMail class");

      Include System.Web.Mail namespace for the above methods to be visible to the compiler. Deepak Kumar Vasudevan http://deepak.portland.co.uk/

      L 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        Hmm... There have been umpteen articles on this topic in C#.

        MailMessage msg = new MailMessage();
        msg.From = "crawler@deepak.portland.co.uk";
        msg.To = "crawler@deepak.portland.co.uk";
        msg.Subject = "Test";
        msg.Body = "Hi! Hello" +"\nSent Via MailMessage and SmtpMail Class";
        SmtpMail.SmtpServer = "smtp.yourmailserver.yourisp.com";
        SmtpMail.Send(msg);
        SmtpMail.Send("crawler@deepak.portland.co.uk","crawler@deepak.portland.co.uk","Test","Hi! Hello\nSent Via SmtpMail class");

        Include System.Web.Mail namespace for the above methods to be visible to the compiler. Deepak Kumar Vasudevan http://deepak.portland.co.uk/

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        Deepak Kumar Vasudevan wrote: There have been umpteen articles on this topic in C#. But he was asking about SMTP with authentication....;P MyDUMeter: a .NET DUMeter clone

        1 Reply Last reply
        0
        • S Sassan Komeili Zadeh

          Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Try adding the username and password to the front of the URl of the SMTP server. eg user:pass@smtp.isp.net Not sure if it will work though. MyDUMeter: a .NET DUMeter clone

          S 1 Reply Last reply
          0
          • L leppie

            Try adding the username and password to the front of the URl of the SMTP server. eg user:pass@smtp.isp.net Not sure if it will work though. MyDUMeter: a .NET DUMeter clone

            S Offline
            S Offline
            Sassan Komeili Zadeh
            wrote on last edited by
            #5

            Thanks. My Mail Server POP3 account username is: info@xyz.com and when I try what you suggested, I get no answer. Would you suggest another solution? Regards, Sassan

            1 Reply Last reply
            0
            • S Sassan Komeili Zadeh

              Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh

              J Offline
              J Offline
              John Mautari
              wrote on last edited by
              #6

              You may use this class and add the following code to authenticate, just after sending the HELO command: //introduce ourselves buf.Append("HELO "); buf.Append(host); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); buf.Length = 0; if(!AuthLoginPlain(con, user, password)) { // Failed con.Close(); throw .... // throw an error } ... private bool AuthLoginPlain(SmtpConnection con, string user, string pass) { //Envia o comand AUTH LOGIN StringBuilder buf = new StringBuilder(); byte [] b_user = System.Text.Encoding.ASCII.GetBytes(user); byte [] b_pass = System.Text.Encoding.ASCII.GetBytes(pass); string response; string res; string data; int code; buf.Append("AUTH LOGIN"); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); buf.Length = 0; if(code == 334) { //pega ultima resposta menos o codigo de resposta response = response.Substring(4); res = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(response)); if(res == "Username:") { //envia o nome de data = Convert.ToBase64String(b_user); buf.Append(data); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); buf.Length = 0; } if(code != 334) { return false; } response = response.Substring(4); res = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(response)); if(res == "Password:") { // manda senha em plain data = Convert.ToBase64String(b_pass); buf.Append(data); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); if(code != 235) { // falhou! return false; } // se chegou até aqui, ok! return true; } } return false; } Cheers, John

              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