Hello. I used sample code below and created the form to send emails from my smtp server, but it only send email to postmaster http://support.Winhost.com/KB/a650/how-to-send-email-in-aspnet.aspx for example if I want to send email from postmaster.mydomain.com to [email protected] is complaint that Mailbox unavailable. The server response was: <[email protected]> No such user here Any Ideas what should I change in this code <%@ Page Language="VB" %> <%@ Import Namespace="System.Net.Mail" %> <script runat="server"> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim strFrom = "[email protected]" Dim strTo = "[email protected]" Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo)) MailMsg.BodyEncoding = Encoding.Default MailMsg.Subject = "This is a test" MailMsg.Body = "This is a sample message using SMTP authentication" MailMsg.Priority = MailPriority.High MailMsg.IsBodyHtml = True 'Smtpclient to send the mail message Dim SmtpMail As New SmtpClient Dim basicAuthenticationInfo As New System.Net.NetworkCredential("[email protected]", "password") SmtpMail.Host = "mail.mydomain.com" SmtpMail.UseDefaultCredentials = False SmtpMail.Credentials = basicAuthenticationInfo SmtpMail.Send(MailMsg) lblMessage.Text = "Mail Sent" End Sub </script> <html> <body> <form runat="server"> <asp:Label id="lblMessage" runat="server"></asp:Label> </form> </body> </html>
Try using another email address other then [email protected]. Make a test script and hard code the From and To address. It is much easier to troubleshoot codings when it is simple. For now do not pass any variables. Once you get this script working then you can expand on it.
Thanks Ray, I eliminated all variable and no change, only I can send to the same email or any other valid email in the same domain e.g, I can send from [email protected] to [email protected] if I send from [email protected] to [email protected] it will not work Any other thought, thansk in advance
Whats the complete error message. The symptoms you're having suggest that smtp authetication is not being passed but base off your coding on one of the threads everything looks correct. Where is this page sitting at? It is some subdirectory. I suspect some kind of inheritance occurring with the .Net web.config file. But I can't be sure.