Sending SMTP relay email with VB.net

I have the following code that will work if I specify credentials, but I want to sent this without using credentials.  Can someone tell me how to do this without specifying credentials?  I setup an SMTP relay server that does not require credentials.

Please, no links.  I think it's just one line of code that I don't have right or that needs to be added.

Dim strTo As String = "me@mydomain.com"
Dim strFrom As String = "account@mydomain.com"
Dim strSubject As String = "Subject"
Dim mailClient As New System.Net.Mail.SmtpClient("10.10.10.14", 25)
Dim strBody As String = "message"
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strTo, strSubject, strBody)
'mailClient.UseDefaultCredentials = False
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
mailClient.Send(mailMessage)

Open in new window

LVL 5
bpl5000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

unknown_routineCommented:
UseDefaultCredentials default value is false.


If this is set to false email is sent annoymously.

If you do not want to specify credentials you have to

UseDefaultCredentials=true
0
bpl5000Author Commented:
I tried...

mailClient.UseDefaultCredentials = True

But that did not work.  It does work when I use credentials using this line...

mailClient.Credentials = New System.Net.NetworkCredential("myaccount", "password")

Maybe I need to set mailClient.Credentials equal to something?
0
unknown_routineCommented:
UseDefaultCredentials=true  should always work ,


But you have to realize the above line means smtp server, behid the scenes will use the windows credentails.


So these Credentails should be valid for smtp server. SMTP server always need valid credentails.


In this line:
Are mailClient.Credentials = New System.Net.NetworkCredential("myaccount", "password")


Are my account and password windows credentials?

In Other word make sure windows credentails are valid in SMTP server.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

unknown_routineCommented:
Ahh, I forgot  to mention one important piece of code:


You also need to set the client credentials to the default:

mailClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
0
bpl5000Author Commented:
I added this line, but still can't get it to work.  Here's how the code looks now...

Dim strTo As String = "me@mydomain.com"
Dim strFrom As String = "account@mydomain.com"
Dim strSubject As String = "Subject"
Dim mailClient As New System.Net.Mail.SmtpClient("10.10.10.14", 25)
Dim strBody As String = "message"
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strTo, strSubject, strBody)
mailClient.UseDefaultCredentials = True
mailClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
mailClient.Send(mailMessage)

Open in new window

0
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Take out account name and password and make section for that to "",""
0
bpl5000Author Commented:
I restarted the SMTP server service (it's an IIS SMTP server) and then it worked.  Maybe I need to restart the service after I add an accepted IP to relay from.  Either that or it just needed a restart.  Anyway, it turns out I don't need any of the statements concerning credentials.  This is all I need...

Dim strTo As String = "me@mydomain.com"
Dim strFrom As String = "account@mydomain.com"
Dim strSubject As String = "Subject"
Dim mailClient As New System.Net.Mail.SmtpClient("10.10.10.14", 25)
Dim strBody As String = "message"
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strTo, strSubject, strBody)
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
mailClient.Send(mailMessage)

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.