From: mickey on
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

From: Onur Güzel on
On Jul 1, 7:01 pm, "mickey" <mickmarsh...(a)earthlink.net> wrote:
> 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
From: mickey on
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

"Onur G�zel" <kimiraikkonen85(a)gmail.com> wrote in message
news:c39b9548-7f31-4ad8-9d5f-d548ea40606c(a)j8g2000yqd.googlegroups.com...
On Jul 1, 7:01 pm, "mickey" <mickmarsh...(a)earthlink.net> wrote:
> 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