c# - System.Security.SecurityException when using smtp.gmail.com -


when using code this read post

var smtp = new smtpclient {     host = "smtp.gmail.com",     port = 587,     enablessl = true,     deliverymethod = smtpdeliverymethod.network,     usedefaultcredentials = false,     credentials = new networkcredential("my email", "my password") }; 

i system.security.securityexception: request permission of type 'system.net.mail.smtppermission.

does code have used in special hosting environment or missing somthing obvious?

thanks!

sending email depends on how smtp server configured.

according gmail confiruged need remove line of code 

usedefaultcredentials = false;

just comment line , message send.

 var smtp = new smtpclient         {             host = "smtp.gmail.com",             port = 587,             enablessl = true,             deliverymethod = smtpdeliverymethod.network,             // not use command            // usedefaultcredentials = false,             credentials = new networkcredential("username", frompassword)         }; 

microsoft suggest not use defaultcredentials when possible. see this link clarification.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -