bpl5000
asked on
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.
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)
ASKER
I tried...
mailClient.UseDefaultCrede ntials = True
But that did not work. It does work when I use credentials using this line...
mailClient.Credentials = New System.Net.NetworkCredenti al("myacco unt", "password")
Maybe I need to set mailClient.Credentials equal to something?
mailClient.UseDefaultCrede
But that did not work. It does work when I use credentials using this line...
mailClient.Credentials = New System.Net.NetworkCredenti
Maybe I need to set mailClient.Credentials equal to something?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 .DefaultNe tworkCrede ntials;
You also need to set the client credentials to the default:
mailClient.Credentials = System.Net.CredentialCache
ASKER
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)
Take out account name and password and make section for that to "",""
ASKER
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)
If this is set to false email is sent annoymously.
If you do not want to specify credentials you have to
UseDefaultCredentials=true