简体   繁体   中英

cannot send yahoo email using vb.net

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")

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

雅虎将465端口用于非付费用户(订阅服务)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM