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

    for example if I want to send email from 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 = ""
    SmtpMail.UseDefaultCredentials = False
    SmtpMail.Credentials = basicAuthenticationInfo

    lblMessage.Text = "Mail Sent"
    End Sub
    <form runat="server">
    <asp:Label id="lblMessage" runat="server"></asp:Label>
    Last edited by a moderator: Oct 14, 2015
  2. Ray


    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.
  3. 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