-
Email Client to Client
I am trying to code an event in a vb.net webform to enable two client users to email each other.
The Code I have below is wrong and I think the problem lies in the SmtpServer bit.
Can someone advise me on how to do this?
Thanks alot
Code:
Dim objEmail As New MailMessage()
objEmail.To = "[email protected]"
objEmail.From = "[email protected]"
objEmail.Subject = "Test Email"
objEmail.Body = "Test Email 2"
SmtpMail.SmtpServer = "sendmail.mywebsitehost.com"
Try
SmtpMail.Send(objEmail)
Response.Write("Your E-mail has been sent sucessfully -" & _
"Thank You")
Catch exc As Exception
Response.Write("Send failure: " + exc.ToString())
End Try
-
The code actually looks correct to me at a glance. Are you sure the SMTP server you are using allows relay without authentication? The problem might not be the code, but rather the way the local SMTP relay is configured.
Also if you are sending from an email address that a local relay doesn't recognize, this can cause problems too.
If your testing the page on your local dev server, an outbound filter or firewall might also affect it...
-
One other thing I forgot is:
Try specifying explicitly the encoding type as such:
myMail.BodyEncoding = System.Text.Encoding.ASCII
I really don't think your problem is the code though, sounds like an SMTP authentication or relay problem...
-
Got It!
Thank you for the reply.
Like you said, the code was ok.
The problem was within my email settings on the webserver - I didnt set it up correctly.
All Ok now!
Thanks again