473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Email Question

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
5 1603
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: michaaal | last post by:
I realize this is not solely an ASP question, but I thought you guys might know the answer and I couldn't find anywhere else to post this. If you have suggestions for this I am more than happy to...
3
by: Michael Teja via SQLMonster.com | last post by:
Dear Mr Portas and Mr Sommarskog, Cause I am a newbie in sql, can I ask for your email address? My email Address is mike@ptmb.com Thanx Best Regards
3
by: zek2005 | last post by:
Hi folks! I need help with the following. I made a form so the user can make a question and that question has to be inserted in my database, but before the question (and other information of the...
12
by: ll | last post by:
I am trying to finalize a regular expression in javascript to only allow emails with a certain domain to be valid. Here is what I have so far: var emailFilter2=/\@aol.com/;...
5
by: canajien | last post by:
I have a form that stores information in a table, but I also need it to send an email when a specific question, among the many, is answered with no the question is a simple drop box: <select...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.