在 DNN 中发送电子邮件



我正在尝试在我正在制作的 DNN 模块中发送电子邮件。但是,虽然它不会崩溃,但电子邮件没有被发送。我认为这与我尝试使用的"发件人电子邮件"有关。我不是 100% 确定我应该使用什么电子邮件作为第一个参数。

Protected Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click
    DotNetNuke.Services.Mail.Mail.SendEmail("support@localhost", "myemail@site.com", "EmailTest", "Hello world!")
End Sub

更可能的问题是您没有正确配置 SMTP 设置。要配置 SMTP 设置,请以主机身份登录。然后,转到主机 -> 设置并填写"SMTP 服务器设置"下的字段并保存它们。那里还有一个测试链接来验证它们是否正常工作。

这可能已经很晚了,但我经常使用 Mail.SendMail() 方法,然后手动传递所有 STMP 信息,如下所示,然后在调试时检查返回的消息。(截至DotNetNuke 5.5)

        Dictionary<string, string> hostSettings = HostController.Instance.GetSettingsDictionary();
        string server = hostSettings["SMTPServer"];
        string authentication = hostSettings["SMTPAuthentication"];
        string password = hostSettings["SMTPPassword"];
        string username = hostSettings["SMTPUsername"];
        // using the Mail.SendMail() method allows for easier debugging.
        var message = Mail.SendMail(from, user.Email, String.Empty, subject, body, String.Empty, "HTML", server, authentication, username, password);

游戏也晚了,但我今天早些时候遇到了类似的问题......

DNN sendMail 或 sendEmail 方法自行处理异常,并将其添加到其 DNN 日志中。不幸的是,他们永远不会将所述异常返回到您调用函数的主代码 - 因此您的代码执行得很好!

可以进一步查看其异常表或 UI 中的管理员日志,以获取有关您遇到的特定问题的详细信息。

我更改了我的代码,以使用 System.Net 发送电子邮件并从DNN中的DotNetNuke.Entities.Host.Host对象收集所需的所有信息。这样,我们可以处理错误并让我们的代码解决它:)我最终得到了这样的东西(它在 c# 中,但您可以在 VB.Net 中用略有不同的语法做同样的事情):

//make the email
MailMessage mail = new MailMessage("From@me.com","to@a.com,to@b.com,to@c.com");
mail.Subject = "test subject";
mail.Body = "actual email";
string dnnServerInfo = DotNetNuke.Entities.Host.Host.SMTPServer;
// The above looks like "server.com:port#", or "smtp.server.com:25"
//so we find the colon to get the server name, and port using the index below
int index = dnnServerInfo.IndexOf(':');
//make the SMPT Client
SmtpClient smtp = new SmtpClient();
smtp.Host = dnnServerInfo.Substring(0, index);
smtp.Port = Int32.Parse(dnnServerInfo.Substring(index + 1, dnnServerInfo.Length - index - 1));
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(DotNetNuke.Entities.Host.Host.SMTPUsername, DotNetNuke.Entities.Host.Host.SMTPPassword);
smtp.EnableSsl = DotNetNuke.Entities.Host.Host.EnableSMTPSSL;
//send the email
smtp.Send(mail);

我使用了此处找到的"SendMail"中的部分原始代码来提出这个:https://stackoverflow.com/a/19515503/6659531

祝遇到这个:)的人好运

最新更新