SmtpClient authentication

  • Thread starter Thread starter mickey
  • Start date Start date
M

mickey

I tried that and it got me past the original problem but now it just fails
to send. Something about not being able to connect to the server. I was able
to ping the server so maybe I should try increasing the timeout.

Thanks
Mickey

Hi
I'm trying to add simple email capability to a program I wrote but when I
send the mail the responce from the server indicates thet I need to use
authenticain.
I have no clue as to how to do that. Here is the code I'm using. Can
anyone
help please?

Thanks
Mickey

Public Sub SendMail(ByVal strFrom As String, ByVal strTo As String, ByVal
strSubject As String, _
ByVal strBody As String, ByVal strSMTPServer As String)
Dim FromAddress As New System.Net.Mail.MailAddress(strFrom)
Dim ToAddress As New System.Net.Mail.MailAddress(strTo)
'send the email
Try
Dim insMail As New MailMessage()
With insMail
.From = FromAddress
.To.Add(ToAddress)
.Subject = strSubject
.Body = strBody
End With
Dim emailClient As New SmtpClient(strSMTPServer)
Try
emailClient.Send(insMail)
Catch ex As Exception
MsgBox(ex.Message)
End Try

Catch e As Exception
MsgBox(e.Message)
End Try

End Sub

You need to instantiate a NetworkCredential object like this:

Dim cred as New NetworkCredential _
(username, password)
emailClient.Credentials = cred

HTH,

Onur Güzel
 
Hi
I'm trying to add simple email capability to a program I wrote but when I
send the mail the responce from the server indicates thet I need to use
authenticain.
I have no clue as to how to do that. Here is the code I'm using. Can anyone
help please?

Thanks
Mickey

Public Sub SendMail(ByVal strFrom As String, ByVal strTo As String, ByVal
strSubject As String, _
ByVal strBody As String, ByVal strSMTPServer As String)
Dim FromAddress As New System.Net.Mail.MailAddress(strFrom)
Dim ToAddress As New System.Net.Mail.MailAddress(strTo)
'send the email
Try
Dim insMail As New MailMessage()
With insMail
.From = FromAddress
.To.Add(ToAddress)
.Subject = strSubject
.Body = strBody
End With
Dim emailClient As New SmtpClient(strSMTPServer)
Try
emailClient.Send(insMail)
Catch ex As Exception
MsgBox(ex.Message)
End Try

Catch e As Exception
MsgBox(e.Message)
End Try

End Sub
 
Hi
I'm trying to add simple email capability to a program I wrote but when I
send the mail the responce from the server indicates thet I need to use
authenticain.
I have no clue as to how to do that. Here is the code I'm using. Can anyone
help please?

Thanks
Mickey

 Public Sub SendMail(ByVal strFrom As String, ByVal strTo As String, ByVal
strSubject As String, _
    ByVal strBody As String, ByVal strSMTPServer As String)
        Dim FromAddress As New System.Net.Mail.MailAddress(strFrom)
        Dim ToAddress As New System.Net.Mail.MailAddress(strTo)
        'send the email
        Try
            Dim insMail As New MailMessage()
            With insMail
                .From = FromAddress
                .To.Add(ToAddress)
                .Subject = strSubject
                .Body = strBody
            End With
            Dim emailClient As New SmtpClient(strSMTPServer)
            Try
                emailClient.Send(insMail)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

        Catch e As Exception
            MsgBox(e.Message)
        End Try

    End Sub

You need to instantiate a NetworkCredential object like this:

Dim cred as New NetworkCredential _
(username, password)
emailClient.Credentials = cred

HTH,

Onur Güzel
 
I tried that and it got me past the original problem but now it just fails
to send. Something about not being able to connect to the server. I was able
to ping the server so maybe I should try increasing the timeout.

Thanks
Mickey






You need to instantiate a NetworkCredential object like this:

Dim cred as New NetworkCredential _
(username, password)
emailClient.Credentials = cred

HTH,

Onur Güzel

Besides incresing timeout value, you can also think of enabling SSL by
means of EnableSSL property. The authentication is done with
NetworkCredential object. For more info, you need to read docs of SMTP
server provider if it's not yours.

HTH,

Onur Güzel
 
Back
Top