Sending emails from code

Discussion in 'ASP.NET 2.0' started by Philip Quirke, Feb 15, 2009.

  1. Hi there

    I have just moved my application www.teamyell.comto be hosted by DiscountAsp.Net

    My application sends emails to remind people of upcoming events.

    The domain teamyell.com itself is registered with GoDaddy.
    GoDaddy shows the SMTP being handled by smtp.secureserver.net


    I can't work out how to configure my code so that it can send emails generated on the DiscountAsp.Net server by my code.
    My code (when simplified) reads like this:

    MailAddress ToAddress = new MailAddress("[email protected]");
    MailAddress FromAddress = new MailAddress("[email protected]", "Team Yell");
    MailMessage mailMessage = new MailMessage(FromAddress, ToAddress);
    mailMessage.Headers.Add("Reply-To", "[email protected]" );
    mailMessage.Subject = "The Subject";
    SmtpClient TheClient = new SmtpClient( "XXXXXXXXXXX" );
    TheClient.Send(mailMessage);


    For "XXXXXXX" I have tried localhost (no response), smtp.teamyell.com (, smtp.secureserver.net (Mailbox unavailable)without success.


    What am I doing wrong? What server should I be sending the email to? Do I have to pay for service on an email server before I can send it?


    All help gratefully accepted
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    'localhost' is the correct SMTP host. What error are you getting?

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. You are correct. The SMTP host name should be "localhost". I am not 100% certain of the cause of the problem I had on Sunday. I read in another thread thatit wasimportant that the "FromAddress" was "postmaster".So I did that. Overall, now it works. My code now reads:
    MailAddress ToAddress = new MailAddress("[email protected]");
    MailAddress FromAddress = new MailAddress("postmaster@teamyell.com", "Team Yell");
    MailMessage mailMessage = new MailMessage(FromAddress, ToAddress);
    mailMessage.Headers.Add("Reply-To", "[email protected]" );
    mailMessage.Subject = "The Subject";
    SmtpClient TheClient = new SmtpClient( "localhost" );
    TheClient.Send(mailMessage);


    Thanks for your reply.
     
  4. Is that to prevent spam or something?
    I think I read where you need to use whatever is your Admin email account is to prevent people from sending out fake email using your domain name.
     

Share This Page