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 . 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 .
You might want to browse through our Knowledge Base which provides sample code: http://support.Winhost.com/KB/c263/sample-code.aspx
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
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
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.
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