Error sending Mail

Discussion in 'ASP.NET 2.0' started by cmcluckie, Sep 6, 2009.

  1. I would like to send mail using a third party smtp server on port 25. It seems that my account is blocking port 25 so that my mail client will not work (I am only allow to connect to locahost). How do I send mail? I would prefer NOT to use localhost for my own and discountASP.NETs benifit.

    I have the following code:

    if (!Convert.IsDBNull(email.Rows[0]["Email"])) emailAddy = email.Rows[0]["Email"].ToString();
    if (!Convert.IsDBNull(email.Rows[0]["Server"])) server = email.Rows[0]["Server"].ToString();
    if (!Convert.IsDBNull(email.Rows[0]["Port"])) port = Convert.ToInt32(email.Rows[0]["Port"]);
    if (!Convert.IsDBNull(email.Rows[0]["UserName"])) user = email.Rows[0]["UserName"].ToString();
    if (!Convert.IsDBNull(email.Rows[0]["Password"])) password = email.Rows[0]["Password"].ToString();
    if (!Convert.IsDBNull(email.Rows[0]["Password"])) txtRetypePassword.Attributes.Add("value", "NOPASSWORDHERE");

    SmtpClient client = new SmtpClient(server, port);

    try
    {
    MailMessage message = new MailMessage();
    message.From = new MailAddress(emailAddy);
    message.To.Add(new MailAddress(emailAddy));
    message.Subject = "Test";
    message.Body = "TEst!";

    client.Host = server;
    client.Credentials = new System.Net.NetworkCredential(user, password, string.Empty);
    client.Send(message);

    txtSendWorked.Visible = true;
    txtSendWorked.Text = "Test.";
    }
    catch
    {
    txtSendError.Visible = true;
    txtSendError.Text = "error";
    }
    finally
    {
    client = null;
    }
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    do you mean you want to email our from your web application?

    You should use localhost to send email.

    There really isn't any difference (from receipient point of view) where the mail is coming from.,
     
  3. The application I have created will act more like a mail client. I want my users to be able to use their own SMTP server so I do not need to be worried about what they send and to whom.
     
  4. mjp

    mjp

    If they are mailing from your application you need to be concerned with what they send no matter what SMTP server they use.

    The spamcop-type services and email blackholes of the world (and most importantly, our upstream backbone connection providers) send spam complaints to everyone in the message header, and our network will be in the header as a point of origin regardless of the route.

    That's got nothing to do with your technical question, but it's something you have to consider. You are ultimately responsible for what your users send through an application such as that.
     

Share This Page