Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29919

Sending mail through C# with gmail is not working after deploying to host

$
0
0

I am trying to send mail through Gmail. I am sending mail successfully when I am testing on localhost, but this does not work when I upload it to a web host. I am seeing this type of error:

Request for the permission of type System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Whenever I am using port 25 get this type of error below:

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

Below is my code of send email.

MailMessage mail = new MailMessage("host@gmail.com","User@gamil.com");

SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");              
mail.Subject = "Any String" 
mail.Body = mailbody;
mail.IsBodyHtml = true;
SmtpServer.Port = 587;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@gmail.com","123");               
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);

Is there any solution? Please suggest to me!


Viewing all articles
Browse latest Browse all 29919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>