Results 1 to 4 of 4

Thread: SMTP Exception - Message could not be sent

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Location
    Latrobe, PA
    Posts
    6

    Question SMTP Exception - Message could not be sent

    Hello everyone,

    I'm creating an application for my own use that allows me to notify my lawnmowing customers when their grass was last cut, how much they owe, etc.

    The application uses an SMTP client to send a MailMessage to the customers through my Yahoo! online email account. The code for sending the message is as follows:

    Code:
    Dim notification As New MailMessage
    notification.Subject = "Grass Tracker Notification"
    notification.To.Add("[email protected]")
    notification.From("[email protected]")
    notification.Body(emailbodystringcreatedearlier)
    
    Dim Smtp As New SMTPClient()
    Smtp.Host = "smtp.mail.yahoo.com"
    Smtp.Port = "995"
    Smtp.Credentials = New System.Net.Credentials("username", "password)
    Smtp.EnableSsl = True
    Smtp.Send(notification)
    However, every time I try to send the message I get an error message that says "Smtp Exception" and "Message could not be sent" or something of that sort. I have tried the following to remedy the problem:

    - Using different ports and clients found online
    - Using a "Try...Catch" method to handle the exception. Every time I attempt to send the message the exception is thrown

    Can anyone offer some advice on how to fix this? The exception is rather vague and doesn't offer a whole lot on what needs changed, like an improper port or something.

    All advice is appreciated and Thanks,
    Josh

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: SMTP Exception - Message could not be sent

    Your code contains a typo, the "password" is missing the closing double quote.

    Why not post the complete text of the exception (ex.ToString())? It should provide a clue to why the email hasn't been sent.

    Also, are you able to send emails from the specific account using an email client?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Location
    Latrobe, PA
    Posts
    6

    Re: SMTP Exception - Message could not be sent

    honeybee,

    Thanks for the help. Here is an abridged version of the error message:

    Code:
    System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 98.136.185.95:995
    This is evidently some kind of trouble connecting to the port; I may have to try some other ports that I find online.

    This is also the fixed code:

    vb Code:
    1. Dim notification As New MailMessage
    2.             notification.Subject = "Grass Tracker Notification"
    3.             notification.To.Add("[email protected]")
    4.             notification.From = New MailAddress("[email protected]")
    5.             notification.Body = "Hey There!"
    6.  
    7.             Dim Smtp As New SmtpClient()
    8.             Smtp.Host = "smtp.mail.yahoo.com"
    9.             Smtp.Port = "995"
    10.             Smtp.Credentials = New System.Net.NetworkCredential("username", "password")
    11.             Smtp.EnableSsl = True
    12.             Smtp.Send(notification)
    13.         Catch ex As SmtpException
    14.             TextBox1.Text = ex.ToString
    15.         End Try

    Also, could you describe how to send messages as an EmailClient? I haven't heard of this before and I'd like to give it a try.

    Thanks,
    Josh

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: SMTP Exception - Message could not be sent

    Are you sure you are connecting to the correct IP address and most importantly the correct SMTP port? Also do you require SSL or any other SMTP authentications enabled?

    By an email client I mean setting up this email account ([email protected]) onto your computer in your Outlook Express/Outlook/Thunderbird or whatever email app you are using, and trying to send an email out from this account. If you are not comfortable with the raw code, it might be better to set up this account in your email client and try sending a sample email to another email account. You can check and tweak the SMTP settings in the email client till the email is successfully sent. Once that is done, you can use the same settings in your above code.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width