Send email failing

Discussion in 'ASP.NET / ASP.NET Core' started by davidsimmonds, Apr 18, 2011.

  1. I use the following code to send email. I cannot use localhost as the server since it will only work on the live site, not on my dev computer. So I use the smtp server that I have been given by discountasp.net. The Send method returns an error "Mailbox unavailable. The server response was: <david@simmonds.ca> No such user here".

    Do I have to specify something special for user?

    mail.From = new MailAddress("NoReply@charitycheck.ca");
    mail.Subject = "Charity Check";
    mail.Body = RadEditor1.Content;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = ConfigurationManager.AppSettings["SMTP"];
    System.Net.NetworkCredential cred = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPUser"],
    ConfigurationManager.AppSettings["SMTPPassword"]);
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = cred;
    smtp.Send(mail);
     
  2. I am getting the same error and banging my head on it.

    If I find the answer I will let you know as well.
    I am trying something simillar using my smtp with a local desktop vb.net code.

    Every email I try to send to ( other than my own ) fails with this exception.

    My code is as follows:

    Public Sub SendEmail()
    Dim sendMail As New Net.Mail.SmtpClient
    Dim userToken As New Object

    With sendMail

    .Host = _Host
    .Port = _Port
    .Credentials = New Net.NetworkCredential(_CredentialEmailAddr, _CredentialPassword)
    .UseDefaultCredentials = False

    End With

    sendMail.Send(_MailMessage)
    End Sub

    ====
    where _MailMessage is of the proper type.

    If I use my smtp settings from a different hosting service - ANY email goes through. If I switch it to be the settings for dasp.

    smtp.mydomainatdasp.com
    miro@mydomainatdasp.com
    <password>
    Port 587

    the exception will fail - unless I am sending to an email address in my own domain name.

    I have also tried to .UseDefaultCredentials set this to True as well and same results.

    So it defenitly is a setting somewhere on DASP smtp ( as the other hosting service smtp works fine ) - but I do not know now as to what else to check.

    If anyone has any answers im all ears.
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    This error usually means that SMTP authentication failed.

    Try this test code

    <%@ Import Namespace="System.Net" %>
    <%@ Import Namespace="System.Net.Mail" %>

    <script language="C#" runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    //create the mail message
    MailMessage mail = new MailMessage();

    //set the addresses
    mail.From = new MailAddress("postmaster@mydomain.com");
    mail.To.Add("postmaster@mydomain.com");

    //set the content
    mail.Subject = "This is an email";
    mail.Body = "This is from system.net.mail using C sharp with smtp authentication.";
    //send the message
    SmtpClient smtp = new SmtpClient("smtp.domain.com");

    NetworkCredential Credentials = new NetworkCredential("postmaster@mydomain.com", "password");
    smtp.Credentials = Credentials;
    smtp.Send(mail);
    lblMessage.Text = "Mail Sent";
    }
    </script>
    <html>
    <body>
    <form runat="server">
    <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
    </body>

    let me know if that works.
    </html>
     
  4. Hi Bruce,

    One big difference in your code vs my code.

    I took the smtp credentials and made a windows forms program that sends an email uses SMTP.

    Sending out of the asp.net program works just fine.

    Sending out of local machine -> smtp -> outside email failes
    Sending out of local machine -> smtp -> miro@mydomainatdasp.com passes

    To be fair - i probably shouldnt have posted / continued the issue in the aps.net 4.0 heading.

    I didnt realize I did until just now.

    But looks to be a simillar issue.
     
  5. Bruce

    Bruce DiscountASP.NET Staff

    SMTP error message is really cryptic.

    If the SMTP credential is wrong (wrong uid / password), you can send to a local domain on the mail server but it will fail when you try to relay to a domain outside of the mail server.

    Check your login / password to make sure it is ok.
     
  6. sending email from website

    They should try this it worked for me

    web.config

    <system.net>
    <mailSettings>
    <smtp>
    <network host="localhost.domain.com"
    password="********"
    userName="postmaster@domain.com" />
    </smtp>
    </mailSettings>
    </system.net>

    Using in c#

    using System.Net;
    using System.Net.Mail;

    Code

    SmtpClient sc = new SmtpClient("localhost.domain.com");
    StringBuilder sb = new StringBuilder();
    MailMessage msg = null;

    sb.Append("Message : " + Message + "\r\n");

    msg = new MailMessag(SenderEmail, "postmaster@domain.com", Subject, sb.ToString());

    sc.Send(msg);
     

Share This Page