Email Question

G

Guest

When I send an email (basically a sms to a phone) from ms outlook it works
fine. When I try to send it pragmatically I get an error stating that it
can’t relay for <the email address>

Try

If Not strMailSv = "" Then
If Not msgTo = "" Then

Dim message As New MailMessage(sMailFrom, _
msgTo, _
sMailSubject, _
sTextBody)
Dim emailClient As New SmtpClient(strMailSv)
emailClient.Send(message)

'MsgBox("Message Sent")
Else
MsgBox("No recepiant specified",
MsgBoxStyle.Critical, "Mail")
End If
Else

MsgBox("No mail server specified", MsgBoxStyle.Critical,
"Mail")
End If

Catch ex As Exception
MsgBox(ex.ToString())
End Try

I have tried "emailClient.UseDefaultCredentials = True" and all I get is a
time out.
Is there a way to send it and authenticate with the server using a password
and user name I specify, to send it?
 
B

Branco Medeiros

Andrew said:
When I send an email (basically a sms to a phone) from ms outlook it works
fine. When I try to send it pragmatically I get an error stating that it
can't relay for <the email address>

*Maybe* you need to sepecify your full smtp server (e.g.
"smtp.gmail.com").
Also, instead of using default credentials, you may need network
credentials:

SmtpClient.Credentials = _
System.Net.CredentialCache.NetworkCredentials

I'll try to setup an smtp account to test it here and see what we can
get.

HTH.

Regards,

Branco.
 
G

Guest

I still get the same timeout message. could it be in the way I am coding it?

Try

If Not strMailSv = "" Then
If Not msgTo = "" Then

Using message As _
New MailMessage(sMailFrom, _
msgTo, _
sMailSubject, _
sTextBody)
Dim emailClient As New SmtpClient(strMailSv, 25)
emailClient.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentials
emailClient.Send(message)

End Using
Else
MsgBox("No recepiant specified",
MsgBoxStyle.Critical, "Mail")
End If
Else

MsgBox("No mail server specified", MsgBoxStyle.Critical,
"Mail")
End If

Catch ex As Exception
MsgBox(ex.ToString())
End Try
 
S

ShaneO

Andrew said:
When I send an email (basically a sms to a phone) from ms outlook it works
fine. When I try to send it pragmatically I get an error stating that it
can’t relay for <the email address>
I once had exactly the same problem, it was caused by not Authenticating
onto the SMTP Server, which is what the "Relay" error is referring to.
(ISP requires Authentication).

That is why it works from Outlook, it is Authenticating for you.

You're almost there, you just need to add -

emailClient.Credentials = New Net.NetworkCredential(strUserName,
strPassWord)

Obviously, add this after your "Dim emailClient as New
SmtpClient(strMailSv, 25)" line.

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
G

Guest

thanks, it working, but some times it take a minute or two to send the email,
but when I close the app, it then send right away. is there a way to get it
to send like that all the time?
 
S

ShaneO

Andrew said:
thanks, it working, but some times it take a minute or two to send the email,
but when I close the app, it then send right away. is there a way to get it
to send like that all the time?
I believe the answer to the Delay problem revolves around the Garbage
Collection of the Mail Message. (I haven't had a problem with this so I
can't be certain).

Try doing the following after your "emailClient.Send(message)" line -

message.Dispose

If you then find a problem that your Message seems to just vanish (ie.
never gets sent) then do it this way -

System.Threading.Thread.Sleep(100)
message.Dispose

Please post back your results so myself (and others) can be aware of
these matters in the future.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top