Send mail through winhost

Discussion in 'Email' started by Datar, May 30, 2012.

  1. Hi,

    I want to know if it's possible to send mail through the smtp that Winhost assign to the site. I'm trying to do it with gmail smtp, when I did some testing using the site in localhost it goes perfect but when I published the site it can't send mails :confused:.

    Could you explain me what´s going wrong??? I already read about SmtpServer.EnableSsl = false; using SMTP, but it stills not working.


    Thank you for your help :).
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    Last edited by a moderator: Oct 14, 2015
  3. check the port on your smtp object. are you using SMTP 25?

    have you tried port 587?
     
    Last edited by a moderator: Oct 14, 2015
  4. I'm using the 587. This is my code:

    try
    {
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("[email protected]");
    mail.To.Add("[email protected]");
    mail.Subject = subject;
    mail.Body = "Body";
    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "xx");
    SmtpServer.EnableSsl = false;
    SmtpServer.Send(mail);
    }
    catch (Exception)
    {
    // Some code
    }

    Thank you for the reply
     
  5. Elshadriel

    Elshadriel Winhost Staff

    Are you receiving an error message?
     
  6. When I'm running the application at localhost not, but at Winhost the method send() just said that couldn't send the mail. Some time ago I had a similar situation, the problem was that we need to open a port, I don't know if It could be the same problem?


    Thank you
     
    Last edited by a moderator: Oct 14, 2015
  7. Elshadriel

    Elshadriel Winhost Staff

    We don't block any outbound connections, so no ports need to be open. It could be possible that Google doesn't allow relaying from port 25 or 587. You might want to try port 465 with SSL enabled. You should check Google's site to verify the information as it has been a while since I've written code to send through their mail servers.
     
  8. I traced the error and I solved It, I'm sharing that with you if I can help somebody with that. The problem wasn't some port, the code was ok, but I'm getting this error "Demand The type of the first permission that failed was: System.Net.Mail.SmtpPermission The Zone of the assembly that failed was: MyComputer", then I added this line to the web.config:

    <trust level="Full" originUrl="smtp.gmail.com" />

    and now all i'ts working perfect.


    Thank you for you help :)
     
  9. Thanks for posting the follow-up.
     

Share This Page