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 mail using SMTP

Sending mail using SMTP

Scheduled Pinned Locked Moved ASP.NET
helphtmlcombeta-testingcode-review
4 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.
  • E Offline
    E Offline
    Elizabeth Rani
    wrote on last edited by
    #1

    Hi All, Can any body help me with some code to send mail using smtp i have a code but mail is not send to a particular mail id. i have written a code as SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("xyz@gmail.com", "ABC"); message.From = fromAddress;//here you can set address message.To.Add("abc@gmail.com.com");//here you can add multiple to message.Subject = "Feedback";//subject of email message.Body = @"Plain or HTML Text"; smtpClient.Send(message); } catch (Exception ex) { lblmsg.Text = "ERROR : " + ex.Message; } this code works fine but mail is not been send. Thanks in Advance Elizabeth

    B A 2 Replies Last reply
    0
    • E Elizabeth Rani

      Hi All, Can any body help me with some code to send mail using smtp i have a code but mail is not send to a particular mail id. i have written a code as SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("xyz@gmail.com", "ABC"); message.From = fromAddress;//here you can set address message.To.Add("abc@gmail.com.com");//here you can add multiple to message.Subject = "Feedback";//subject of email message.Body = @"Plain or HTML Text"; smtpClient.Send(message); } catch (Exception ex) { lblmsg.Text = "ERROR : " + ex.Message; } this code works fine but mail is not been send. Thanks in Advance Elizabeth

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      Elizabeth Rani wrote:

      this code works fine

      Really? Have ever looked at lblmsg? Nowhere did you set the Host, Port, EnableSsl, and Credentials properties of the SmtpClient. It must fail because of that. Next, some mail providers check that the From property of the MailMessage is the address of the user identified by the UserName of the Credentials - in case of doubt, they'll refuse to send the mail.

      E 1 Reply Last reply
      0
      • B Bernhard Hiller

        Elizabeth Rani wrote:

        this code works fine

        Really? Have ever looked at lblmsg? Nowhere did you set the Host, Port, EnableSsl, and Credentials properties of the SmtpClient. It must fail because of that. Next, some mail providers check that the From property of the MailMessage is the address of the user identified by the UserName of the Credentials - in case of doubt, they'll refuse to send the mail.

        E Offline
        E Offline
        Elizabeth Rani
        wrote on last edited by
        #3

        Hi, Can you help me some sort of code please. Thanks in advance

        1 Reply Last reply
        0
        • E Elizabeth Rani

          Hi All, Can any body help me with some code to send mail using smtp i have a code but mail is not send to a particular mail id. i have written a code as SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("xyz@gmail.com", "ABC"); message.From = fromAddress;//here you can set address message.To.Add("abc@gmail.com.com");//here you can add multiple to message.Subject = "Feedback";//subject of email message.Body = @"Plain or HTML Text"; smtpClient.Send(message); } catch (Exception ex) { lblmsg.Text = "ERROR : " + ex.Message; } this code works fine but mail is not been send. Thanks in Advance Elizabeth

          A Offline
          A Offline
          antish1
          wrote on last edited by
          #4

          Dim strMsg As String strMsg = txtMessage.Text If strMsg.Length >= 140 Then strMsg = strMsg.Substring(1, 140) End If mTo = Trim(txtToNumber.Text) & _ Trim(cboCarrier.SelectedItem.ToString()) mFrom = Trim(txtFrom.Text) mSubject = Trim(txtSubject.Text) mMsg = Trim(txtMessage.Text) mMailServer = ConfigurationManager.AppSettings.Get("MyMailServer") mPort = ConfigurationManager.AppSettings.Get("MyMailServerPort") Try Dim message As New MailMessage(mFrom, mTo, mSubject, mmsg) Dim mySmtpClient As New SmtpClient(mMailServer, mPort) mySmtpClient.UseDefaultCredentials = True mySmtpClient.Send(message) MessageBox("The mail message has been sent to " & _ message.To.ToString()) Catch ex As FormatException MessageBox("Format Exception: " & ex.Message) Catch ex As SmtpException MessageBox("SMTP Exception: " & ex.Message) Catch ex As Exception MessageBox("General Exception: " & ex.Message) End Try End Sub

          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