开发者

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 g开发者_JS百科mail) 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜