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 -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -