SMTP server cannot send emails from C # asp.net hosting

Good day to all. I wrote a project based on asp.net mvc3. Part of the project is based on sending emails from my application.

public void SendEmail(string address, string subject, string message, int id) { string email = " emailname@gmail.com "; string password = "somepassword"; var loginInfo = new NetworkCredential(email, password); var msg = new MailMessage(); var smtpClient = new SmtpClient("smtp.gmail.com", 587); msg.From = new MailAddress(email); msg.To.Add(new MailAddress(address)); msg.Subject = subject; msg.Body = message; msg.IsBodyHtml = true; msg.Attachments.Add(new Attachment(Server.MapPath("~/Content/StudentPdf/student" + id + ".pdf"))); smtpClient.EnableSsl = true; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = loginInfo; smtpClient.Send(msg); } 

This code works locally, sending emails perfectly. But when I upload it to the hosting, it causes an error

the SMTP server requires a secure connection or the client was not authenticated. Server response: 5.5.1 Authentication required.

I tried to change the port to 465, but then it will get me a tcp_ip error on the hosting. And one more thing: and when users try to send emails from this mailbox, tell me what suspicious activity is in the application. This is because my hosting is in one country and I am in another country.

I have no idea what to do next. I tried searching on the Internet and found something around two registration levels, but I don’t understand how I need to implement it in my method.

I am using arvixe hosting. Perhaps others have the same problems?

+7
c # email asp.net-mvc-3 hosting
source share
1 answer

Log in to your gmail account manually and resolve the IP address of your hosting in gmail settings. That is why I think it works fine on your local computer. The same thing happened to me, and after that there were no problems.

+1
source share

All Articles