简体   繁体   English

在ASP.NET中发送电子邮件而无需登录

[英]Sending Email in ASP.NET without Logging in

In my search for a way to send email on my webapp through a form, the only solution I got working was an old MSDN solution for a WebMail helper where it had me hardcode the credentials for an email to send through. 在寻找通过表单在Web应用程序上发送电子邮件的方法时,我得到的唯一解决方案是针对WebMail助手的旧的MSDN解决方案,在该解决方案中,我需要对发送电子邮件的凭据进行硬编码。

Right, off the bat, I know this is not ideal. 没错,我知道这并不理想。 Is there an easy way to send this mail out from a WebMail default so I can remove the login credentials and not look so amateurish??? 有没有一种简单的方法可以从WebMail默认值发送此邮件,以便我可以删除登录凭据,而不会显得那么业余???

@{
var customerName = Request["customerName"];
var customerEmail = Request["customerEmail"];
var customerPhone = Request["customerPhone"];
var customerRequest = Request["customerRequest"];
var errorMessage = "";
var toMail = "user@mail.com";
var debuggingFlag = false;
try
{
    // Initialize WebMail helper
    WebMail.SmtpServer = "smtp.gmail.com";
    WebMail.SmtpPort = 587;
    WebMail.UserName = "user@mail.com";
    WebMail.Password = "Password!";
    WebMail.From = "user@mail.com";
    WebMail.EnableSsl = true;

    // Send email
    WebMail.Send(to: toMail,
        subject: "Quote/Info request from - " + customerName,
        body: customerPhone + customerRequest
    );
}
catch (Exception ex)
{
    errorMessage = ex.Message;
}

See the mailSettings element of you web.config file. 请参阅web.config文件的mailSettings元素。

For some reason the msdn page on the WebMail class recommends the _AppStart.cshtml file as a suitable place to configure these settings. 由于某些原因, WebMail类上的msdn页建议使用_AppStart.cshtml文件作为配置这些设置的合适位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM