cannot relay through smtp server in asp.net

dave_e_work
dave_e_work used Ask the Experts™
on
him hope you can help, I have the following code:

Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New Net.NetworkCredential("enquiries@mydomain.com", "mypassword")
SmtpServer.Host = "smtp.mydomain.com"
SmtpServer.EnableSsl = False
mail.From = New MailAddress("enquiries@mydomain.com", "Mr Smith", System.Text.Encoding.UTF8)
mail.To.Add("me@mydomain.com")
mail.Subject = "Website Contact Entry"
mail.IsBodyHtml = True
mail.Body = "my message"
SmtpServer.Send(mail)

The thing is, it works perfect when I run it from my localhost, as soon as it is live, it doesn't work, doesn't show any errors and looks like it has sent it.

Can you point me in the right direction?

thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You should make some changes to your smtp server to accept and relay messages from your web server. Most smtp servers by default do not accept messages from other machines. If someone else administers your smtp server, then ask them to "allow relaying" for the IP address of your web server.
When you use SMTP authentication, relaying should not be a problem. Your credentials might have not been passed properly. If server supports SSL for SMTP which is port 567 trying using
SmtpServer.EnableSsl =True,

Or see below configuration. It should work .


MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(txtSMTPUser.Text, txtSMTPPass.Text);
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(message);
litStatus.Text = "Message Sent";
You need to confirm the relay server
SmtpServer.Host = "smtp.mydomain.com"

Issue is in the address.
Gary DavisDir Internet Svcs

Commented:
Is there anything in the Event Viewer to help pinpoint the failure?
In IIS you have to add the ip-adres of server to enable relaying from that adress
I managed to figure this out, we were sending to and from the same email address, hence the authentication issues. Thanks for your help though.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial