Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVCMailer smtp邮件设置以编程方式设置配置设置_C#_Asp.net_Asp.net Mvc 3_Smtpclient_Mvcmailer - Fatal编程技术网

C# MVCMailer smtp邮件设置以编程方式设置配置设置

C# MVCMailer smtp邮件设置以编程方式设置配置设置,c#,asp.net,asp.net-mvc-3,smtpclient,mvcmailer,C#,Asp.net,Asp.net Mvc 3,Smtpclient,Mvcmailer,MVCMailer使用web.config文件中的smtp设置,如下所示: <system.net> <mailSettings> <smtp from="some-email@gmail.com"> <network enableSsl="true" host="smtp.gmail.com" port="587" userName="some-email@gmail.com" password="valid-passwor

MVCMailer使用web.config文件中的smtp设置,如下所示:

<system.net>
<mailSettings>
      <smtp from="some-email@gmail.com">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="some-email@gmail.com" password="valid-password" />
      </smtp>
</mailSettings>
</system.net>

是否仍然可以在代码中设置SMTP设置?我希望避免将密码保存在web.config文件中

使用具有所需属性的SmtpClient调用
SmtpClientWrapper

SmtpClient client = new SmtpClient("mail.example.com", 995);
SmtpClientWrapper wrapper = new SmtpClientWrapper(client);

我仍然有一个错误,在执行此操作时未指定SMTP主机…我想我需要找到一种方法将包装分配给MVCMailer。啊,好的,我发现了这一点-您需要将包装传递给Send方法。谢谢:)
SmtpClient client = new SmtpClient("mail.example.com", 995);
SmtpClientWrapper wrapper = new SmtpClientWrapper(client);