Error sending email
-
Hi, I have designed ASP.NET C# 3.5 (MySQL) website and it is hosted on shared web server. I have to send email to site users. I have written the all required code, I am sending mail from "info@mysitename.com" to yahoo or gmail but having the following exception. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Line 41: objEmail.Priority = MailPriority.Normal; Line 42: Line 43: SmtpClient smtpClient = new SmtpClient(smtpServer, Convert.ToInt32(port)); Line 44: System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(fromAddress, pwd); Line 45: Thanks
-
Hi, I have designed ASP.NET C# 3.5 (MySQL) website and it is hosted on shared web server. I have to send email to site users. I have written the all required code, I am sending mail from "info@mysitename.com" to yahoo or gmail but having the following exception. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Line 41: objEmail.Priority = MailPriority.Normal; Line 42: Line 43: SmtpClient smtpClient = new SmtpClient(smtpServer, Convert.ToInt32(port)); Line 44: System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(fromAddress, pwd); Line 45: Thanks
Dot-Net-Dev wrote:
ine 43: SmtpClient smtpClient = new SmtpClient(smtpServer, Convert.ToInt32(port)); Line 44:
Everything is pretty self explanatory. The port that you are trying to use to send emails is blocked by your IT team. You need to talk to them and get it unblocked. Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
<mailSettings>
<smtp from="abc@somedomain.com">
<network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>If needed, have a look at this Microsoft Video tutorial: Use ASP.NET to Send Email from a Web Site [^]