1

I'm working with a program that can send email supporting yahoo mail and gmail. And it works in gmail(if the sender utilizes gmail) But it won't work if the sender is using yahoo mail. Here is my code:

    mail.From = New MailAddress(TextBox2.Text)
    mail.To.Add(New MailAddress(TextBox1.Text))
    mail.Subject = TextBox4.Text
    mail.Body = TextBox4.Text



    mail.IsBodyHtml = True

    Dim client2 As SmtpClient = New SmtpClient("smtp.mail.yahoo.com", 25)
    Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 587)




    client.EnableSsl = True
    client.Credentials = New System.Net.NetworkCredential(TextBox2.Text, TextBox3.Text)


    Try
        client.Send(mail)
    Catch ex As Exception
        MessageBox.Show("Sending email failed. Please Try again")
2
  • It would be interesting to know the details of the exception.
    – MarkJ
    Dec 27, 2009 at 7:40
  • A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll The program '[2660] rewmail.vshost.exe: Managed' has exited with code 0 (0x0).
    – user225269
    Dec 27, 2009 at 8:09

2 Answers 2

1

Looks like you might be using the wrong port? Try this

Dim client2 As SmtpClient = New SmtpClient("smtp.mail.yahoo.com", 587)

EDIT OK, that didn't work. Actually, isn't the SMTP address also wrong?

Dim client2 As SmtpClient = New SmtpClient("plus.smtp.mail.yahoo.com", 587)

You could also wrap the whole program in a Try block and catch any SmtpException and write out the special SmtpStatusCode:

Try 
  ' Blah blah '
Catch (SmtpException e)
   Console.WriteLine("Error: {0} {1}", e.StatusCode, e.ToString) 
End Try
0
0

Yahoo uses Port 465 for non-paying users (subscription services).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.