在asp.net mvc中发送电子邮件,而无需像在php中那样使用凭据 [英] Send email in asp.net mvc without using credentials like in php
本文介绍了在asp.net mvc中发送电子邮件,而无需像在php中那样使用凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 ASP.NET MVC
中发送电子邮件,而无需使用 PHP
中的凭据.
Is it possible to send an email in ASP.NET MVC
without using credentials like in PHP
.
在 PHP
中,我仅使用 mail
方法来发送电子邮件,而无需使用任何凭据.如何在 C#
中做同样的事情?
In PHP
I simply use the mail
method to send an email without using any credentials. How can I do the same thing in C#
?
推荐答案
它将使用默认凭据.
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(EMAIL_FROM_WHICH_YOU_WANT_TO_SEND_EMAIL);
mail.To.Add(new MailAddress(EMAIL_TO_WHOM_YOU_WANT_TO_SEND_EMAIL));
mail.Subject = YOUR_SUBJECT;
mail.Body = BODY_OF_EMAIL;
mail.IsBodyHtml = true/false[BASED_ON_YOUR_BODY];
smtpClient.Send(mail);
,您需要将其添加到 web.config
文件中.
and you'll need to add this in web.config
file.
<system.net>
<mailSettings>
<smtp from="[URL]" deliveryMethod="network">
<network host="localhost" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
这篇关于在asp.net mvc中发送电子邮件,而无需像在php中那样使用凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文