How to send smtp email without using the localhost

Discussion in 'ASP.NET 2.0' started by bfancett, Sep 8, 2008.

  1. I am trying to set-up smtp email in my website, however when I use smtp.mydomain.com as the network host in the web.config file I get random errors regarding Greylisting and unable to connect to remote server at IP Address 64.XX.XXX.XX.

    The Discountasp.net helpdesk people keep telling me to use local host instead of the smtp.mydomain.com for the network host in my mailsettings section of the web.config file. My response to them is that I know this will work once I publish my pages to the server, but when I am testing my site at home, this does me no good at all.

    Does anyone know, what settings I can use for my Discountasp.net email account in the web.config file that will work both once I publish my pages to the server, and also from home?

    Thank you,

    Brian Fancett
     
  2. Bruce

    Bruce DiscountASP.NET Staff

  3. Bruce,


    Good reference article, but the code that this shows uses the local host. Also, this code is for programmatically sending an email message. This is not what I am trying to accomplish. The asp.net Membership Provider takes care of all this, but you still have to define your smtp mail settings in the web.config file. Using "localhost" in the web.config file will only work once the pages are published to the server at discountasp.net. For debugging purposes, "localhost" will not work, because I do not have a local smtp server at home (localhost).


    I am looking for the web.config configuration for mailsettings (smtp client) that will work for the discountasp.net smtp servers from BOTH the servers at discountasp.net and myoffice (local development environment).
     
  4. I have also been trying to do the same thing (ie not use localhost). I was also told to use port 25, but that did not work either. For development purposes I decided to gmail's smtp server.

    //SmtpClient smtpClient = new SmtpClient(@"smtp.rbqsoft.com", 25);
    SmtpClient smtpClient = new SmtpClient(@"smtp.gmail.com", 587);
    smtpClient.EnableSsl = true;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.UseDefaultCredentials = false;
    //smtpClient.Credentials = new System.Net.NetworkCredential(@"userName@rbqsoft.com", "mypassword");
    smtpClient.Credentials = new System.Net.NetworkCredential("userName@gmail.com", "myPassword");

    smtpClient.Send(mailMessage);

    The code for gmail works but changing it to my host site, results in a timeout. For now, will just switch to localhost when I deploy the application. I hope you get a better solution to your original problem, but this may temporarily help you move on.
     
  5. mjp

    mjp


    You need to authenticate any connections to the SMTP server with an email account username/password, that may be why your connections are failing. Messages sent from a server on our network are assumed to come from one of our users and bypass the authentication requirement (which is why you don't have to authenticate when using localhost).
     
  6. I am authenticating. Here is the section of my web.config minus my password of course:


    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="smtp.coeusdev.com" password="XXXXXXXXXX" userName="[email protected]"/>
    </smtp>
    </mailSettings>
    </system.net>


    This doesn't work for me.
     
  7. Hi Brian,

    I dont think you need to define the delivery method as network or set the port either if you are using smtp credentials.

    This works for me.
    ...
    ' Populate the smtp server name
    strSmtpMailServer = "smtp.your.com"

    ' Populate the smtp user name credential
    strSmtpUsername = "[email protected]"

    ' Populate the smtp password credential
    strSmtpPassword = "password"

    ' Create the NetworkCredential object
    Dim objNetworkCredential As New System.Net.NetworkCredential(strSmtpUsername, strSmtpPassword)

    ' Create the SmtpClient object
    Dim objSmtpClient As New System.Net.Mail.SmtpClient(strSmtpMailServer)

    ' Parse the NetworkCredential to the smtpclient object
    objSmtpClient.Credentials = objNetworkCredential

    ' Send the message.
    objSmtpClient.Send(objMailMessage)
    ...


    Alan
     
  8. This works for me on my development machine at home...I use this with the built in CreateUserWizard


    Check out http://aspnet.4guysfromrolla.com/articles/062508-1.aspx


    In the web.config<configuration>
    <!-- Add the email settings to the <system.net> element -->
    <system.net>
    <mailSettings>
    <smtp>
    <network
    host="smtp.yourdomain.com"
    port="25"
    userName="username"
    password="password" />
    </smtp>
    </mailSettings>
    </system.net>


    <system.web>
    ...
    </system.web>
    </configuration>
     

Share This Page