By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

Email Question

P: n/a
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?
Feb 1 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Andrew wrote:
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.

Feb 2 '07 #2

P: n/a
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.DefaultNetworkCredentia ls
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

"Branco Medeiros" wrote:
Andrew wrote:
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.

Feb 2 '07 #3

P: n/a
Andrew wrote:
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.
Feb 2 '07 #4

P: n/a
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?

"ShaneO" wrote:
Andrew wrote:
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.
Feb 2 '07 #5

P: n/a
Andrew wrote:
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.
Feb 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.