Send Email using ASP.NET

Discussion in 'Site Programming, Development and Design' started by khalilim, Sep 21, 2009.

  1. 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 someone@yahoo.com is complaint that

    Mailbox unavailable. The server response was: <someone@yahoo.com> 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 = "postmaster@mydomain.com"
    Dim strTo = "postmaster@mydomain.com"
    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("postmaster@mydoamin.com", "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>
    :)
     
    Last edited by a moderator: Oct 14, 2015
  2. Ray

    Ray

    Try using another email address other then someone@yahoo.com. 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.
     
  3. Ray

    Ray

    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.
     
  4. FredC

    FredC Winhost Staff

    The error you are seeing usually means that the SMTP authentication information is invalid.
     

Share This Page