这是我在Contactus控制器中的Methode。
[HttpPost]
public string Sendemail(string username, string useremail, string usermobile)
{
var success = "success";
var fromemail = useremail;
var toemail = WebConfigurationManager.AppSettings["email"];
var password = WebConfigurationManager.AppSettings["password"];
var body = userdescription;
var mobile = usermobile;
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(toemail, password)//here i dont want to speciefie my pasword
// Credentials=new NetworkCredential()
};
using (var message = new MailMessage(fromemail, toemail)
{
Body = body
}) { smtp.Send(message); }
return success.ToString();
}
在我的WebConfig文件中,我指定了我的用户名和密码,如果我尝试发送邮件可以正常工作,但我不希望在we.config文件中指定密码,我只需要指定电子邮件而不是密码...
这是我的Webconfig代码...
<appSettings>
<add key="email" value="[email protected]"/>
<add key="password" value="xxxxxxxxx"/>
</appSettings>
如果我喜欢它的意思,但是我不想在web.config中指定密码,我也只想指定电子邮件地址。
所以帮我怎么做..
提前致谢...
您不能在smtp.gmail.com
没有身份验证的情况下使用,这是Google政策。
要解决此问题,您可以:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句