Cant send external email...

Discussion in 'Site Programming, Development and Design' started by Bobter, Nov 20, 2009.

  1. Hi Guys,

    I'm doin something stupid i think, I can send internal email with this code -

    Dim mail As New MailMessage()

    mail.From = New MailAddress("[email protected]")
    mail.To.Add("[email protected]")

    mail.Subject = "This is an email"
    mail.Body = "This is a test message."

    Dim smtp As New SmtpClient("mail.mydomain.com")

    Dim Credentials As New System.Net.NetworkCredential("[email protected]", "password")

    smtp.Send(mail)

    but when i change the mail.add.to variable to a googlemail account it gives the following error -

    "Mailbox unavailable. The server response was: <[email protected]> No such user here"

    Any thoughts??
     
  2. bypass relay settings?
     
  3. Ray

    Ray

    I don't think you are passing the SMTP authentication correctly on your app.

    Make sure you add these line in...

    SmtpClient smtp = new SmtpClient("mail.mydomain.com");

    NetworkCredential Credentials = new NetworkCredential("[email protected]", "password");
    smtp.Credentials = Credentials;
    smtp.Send(mail);
    lblMessage.Text = "Mail Sent";

    Also review this kb article.

    http://support.Winhost.com/KB/a650/how-to-send-email-in-aspnet.aspx
     
    Last edited by a moderator: Oct 14, 2015
  4. I'm having this exact same problem, and I've verified that the code is exactly like the sample and the article that Ray posted. When the From and To addresses are setup on mydomain, it works fine. When the To address uses some other domain, I get the "Mailbox unavailable. The server response was" <[email protected]> No such user here" message.

    I'm running this code on a local WinForm app as opposed to an aspx page on the server, if that makes a difference. Is there a way to make this work? Seems like Bobter figured it out since he never wrote back.
     
  5. Ray

    Ray

    Paste a copy of your code on this thread.
     
  6. Here it is:

    MailMessage email = new MailMessage();
    email.From = new MailAddress("[email protected]");
    email.To.Add("[email protected]");
    email.Body = "test message";
    email.Subject = "Subject Title";
    SmtpClient client = new SmtpClient("mail.mydomain.com");
    NetworkCredential creds = new NetworkCredential("[email protected]", "password");
    client.Credentials = creds;
    client.Send(email);
     
  7. Ray

    Ray

    What is the full error message you are getting or are you getting a bounce back message? First make sure the email you are sending to is a good and valid email address. If you are passing variables to do the smtp authentication, try hard coding it in first. Lastly, make sure the SMTP authentication has the correct email address and password to authenticate itself against our SMTP server.
     
  8. The error is the same message Bobter was getting:
    "Mailbox unavailable. The server response was: <[email protected]> No such user here"

    The email I'm sending to is one of my other emails from another site host (soon to be moved over here because you guys are awesome!)

    There's no variables being used. The code is exactly how it looks here except I'm using the actual domain name and password.

    Does the credentials used in the NetworkCredential() function have to be the [email protected] address? I don't even know what the password for that one is because it was already setup for me and the password was never given anywhere. I created a new user called [email protected] and was able to create a password for that one, so that's what I use for the NetworkCredential() authentication. Could that be the problem? If so, how do I get the password for the [email protected] primary admin account?
     
  9. Ray

    Ray

    No it does not have to be the postmaster account. It can be any existing POP account on our system. The SMTP server you are using (i.e. mail.mydomain.com) are you sure it is pointing to us. Sometimes, the client will forget to update the name servers to point to our DNS servers. So mail.mydomain.com is actually pointing to their old hosting provider.
     
  10. The site I'm working on is a new one that hasn't been hosted anywhere else though. This is the afterglow-fireworks.com account. I've got Outlook setup to send and receive mail on the same smtp server and it's been working fine. I don't get the error when the To address is an email that has the same domain, for example [email protected]. It's only when the domain is somewhere else that it doesn't work. That's the same problem I've seen a few other people report here, except it seems that they found a way around this problem. If I intentionally put the wrong account name or password in the Credentials the error message remains the same. If the From and To address have the afterglow-fireworks.com domain and I intentionally botch the credentials, I don't get the error. It really looks like credentials problem, but what could cause it other than using the incorrect user name and password?
     
  11. Ray

    Ray

    The only way to know is to paste your complete and true code on this thread. The sample code you pasted appears to be correct but then again like you said, it can be a little thing such as a comma or something like that.
     
  12. Here's everything except the real password. The app is just a form with a test button on it, and this is the click event handler for that button. The commented out lines were other things I already tried which did not fix the problem.


    private void button_email_Click(object sender, EventArgs e)
    {
    try
    {
    MailMessage email = new MailMessage();
    email.From = new MailAddress("[email protected]");
    email.To.Add("[email protected]");
    email.Body = "test message";
    email.Subject = "AfterGlow Purchase";
    SmtpClient client = new SmtpClient("mail.afterglow-fireworks.com");
    //client.UseDefaultCredentials = false;
    //client.DeliveryMethod = SmtpDeliveryMethod.Network;
    NetworkCredential creds = new NetworkCredential("[email protected]", "password");
    client.Credentials = creds;
    client.Send(email);
    }
    catch (SmtpException ex)
    {
    MessageBox.Show("Email failed to send: " + ex.Message, "Mail Problem");
    }
    }
     
  13. Ray

    Ray

    Did you import the proper name space to your app to pass smtp authentication?
     
  14. These are all the namespaces I'm using. The System.Net.Mail is the one of interest.

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.Data.SqlClient;
    using System.Net.Mail;
     
  15. OK, I feel like a total retard now. The problem was there was an uppercase letter in the password that should have been a lower case letter! (slapping forhead multiple times)

    I should of tried logging into my smartmail account manually using the user and password pasted from the code just to verify that it was correct (which you told me to do originally... Doh!).

    Anyway, thanks for your fast responses and great support. I can't wait to move my other two websites over here! I love the control panel, and the database access is so much faster than what I am used to. I'm amazed you guys even have the time to spend answering people's questions on this forum. My other host doesn't even have a forum, and they literally charge seven times more than Winhost for the same package!
     
    Last edited by a moderator: Oct 14, 2015
  16. Thanks for the kudos!

    It's always the smallest issues that give us the most problems
     
  17. Having same problem

    Edit: I am not able to send internal emails anymore, though I'm not sure what I changed recently. Do I need to edit anything in the IIS SMTP E-mail feature?


    Hi,

    I am having the same issue with not being able to send external emails. I have double checked that I am using the right password and username combo, I can log in to the SmarterMail client just fine. I am also able to send emails to my account, [email protected] from an external site and vice versa.

    Please help! My code:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Net.Mail;
    using BuddyRating.DataAccess;

    namespace BuddyRating.Domain
    {
    public class Email
    {
    public static string SendWelcomeEmail(string name, string userEmail)
    {
    try
    {
    MailMessage email = new MailMessage();
    email.From = new MailAddress("[email protected]");
    email.To.Add("[email protected]");
    email.Subject = "Welcome to BuddyRating";
    email.Body = "Hi";
    email.IsBodyHtml = true;

    SmtpClient smtp = new SmtpClient("mail.buddyrating.com");
    NetworkCredential credentials = new NetworkCredential("[email protected]", "mypassword");
    smtp.Credentials = credentials;
    smtp.Send(email);
    return "Email sent";
    }
    catch (SmtpException ex)
    {
    return "Email failed to send: " + ex.Message;
    }
    }
    }
    }
     
  18. Ray

    Ray

    What's the exact error message you are getting?
     

Share This Page