Click here to Skip to main content
16,009,728 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
U am tryig to write simple routine to send email from desktop appliation.
For simplicity I have a form with one button. The code is hardcoded but I can add the bells and whistles later. When I run it it debugs OK but comes up with an error "uable to connect to remote server" Any help will be much appreciated.


VB
Imports System.Net.Mail
Imports System.Net

Public Class Form1


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim mFrom, mTo As String
        mFrom = "hostemailaddress@yahoo.co.uk"
        mTo = "targetemailaddress@yahoo.com"
        Dim mPort As Int32
        mPort = 25      'default port for mail server

        Dim email As New MailMessage(mFrom, mTo)
        email.Subject = "Test Subject"        
        email.Body = Hello World
        Dim mySmtpClient As New SmtpClient("yahoo.co.uk", mPort)
        mySmtpClient.UseDefaultCredentials = True

        Dim emailAdr As String
        Dim passwrd As String

        emailAdr = "hostemailaddress@yahoo.co.uk"
        passwrd = "password"
        mySmtpClient.Credentials = New NetworkCredential(emailAdr, passwrd)
        mySmtpClient.Send(email)

        
    End Sub

End Class
Posted
Updated 28-Feb-12 3:50am
v2

You set the wrong port number: Yahoo uses port 587, not 25.
Furthermore, the host should be smtp.yahoo.co.uk:
VB
Dim mySmtpClient As New SmtpClient("smtp.yahoo.co.uk", mPort)
 
Share this answer
 
v2
Thank you for the reply, but it still doesn't work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900