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. SMTP Exception

SMTP Exception

Scheduled Pinned Locked Moved C#
csharpsysadminhelp
2 Posts 2 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.
  • C Offline
    C Offline
    Christiaan Laubscher
    wrote on last edited by
    #1

    Hi I am trying to send an e - mail message. I have supplied the wrong network - credentials so that an exception would hopefully be thrown. However, no exception is thrown. I find this very strange. Heres my code: mailMsg.Subject = m_Subject; // Subject of the E - mail. mailMsg.Body = m_Content; // Content of the E - mail. mailMsg.IsBodyHtml = true; mailMsg.BodyEncoding = System.Text.Encoding.UTF8; mailMsg.To.Add(m_Address); // The address to which the e - mail message must be sent. mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.Never; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(serp_URL); System.Net.NetworkCredential netCred = new System.Net.NetworkCredential(); netCred.UserName = serp_LoginName; netCred.Password = serp_Password; smtp.Credentials = netCred; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; try { smtp.Send(mailMsg); } catch (System.Net.Mail.SmtpFailedRecipientException) { // Or any other exception for that matter. return false; } Any help would be greatly appreciated.

    ChristiaanS

    I 1 Reply Last reply
    0
    • C Christiaan Laubscher

      Hi I am trying to send an e - mail message. I have supplied the wrong network - credentials so that an exception would hopefully be thrown. However, no exception is thrown. I find this very strange. Heres my code: mailMsg.Subject = m_Subject; // Subject of the E - mail. mailMsg.Body = m_Content; // Content of the E - mail. mailMsg.IsBodyHtml = true; mailMsg.BodyEncoding = System.Text.Encoding.UTF8; mailMsg.To.Add(m_Address); // The address to which the e - mail message must be sent. mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.Never; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(serp_URL); System.Net.NetworkCredential netCred = new System.Net.NetworkCredential(); netCred.UserName = serp_LoginName; netCred.Password = serp_Password; smtp.Credentials = netCred; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; try { smtp.Send(mailMsg); } catch (System.Net.Mail.SmtpFailedRecipientException) { // Or any other exception for that matter. return false; } Any help would be greatly appreciated.

      ChristiaanS

      I Offline
      I Offline
      I_AM_ERROR
      wrote on last edited by
      #2

      I have a similar problem, but I'm providing an invalid recipient address instead. I want an exception to be thrown, but none is. After attempting to send my message, I later got an email message from the SMTP server saying the mail was undeliverable (as expected). It seems that the SMTP server accepts the bad email and closes the connection with your program, so your program thinks everything is ok. Then, the SMTP server actually tries to deliver the mail. Does anyone know of a workaround so that your program knows whether or not the message was successfully delivered? Thanks

      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