IMG-LOGO

How to send email programatically in dnn?

andy - 10 Sep, 2013 10151 Views 0 Comment

In this tutorial, we will show you, how you can send an email using the default sending function from DotNetNuke.

To send the email in DNN, you just need to use the following send email function.

/*** SUB FUNCTION TO SEND EMAIL ***/
private void SendMail(string strFrom, string strTo, string strCC, string strBCC, string strSubject, string strBody) {
    /*** Get the host settings information***/
    System.Collections.Generic.Dictionary<string, string=""> hostSettings = DotNetNuke.Entities.Controllers.HostController.Instance.GetSettingsDictionary();
        
    /*** Set the SMTP server details ***/
    string strSMTP = hostSettings["SMTPServer"];

    /*** This is the actual built in function from DNN Framework. ***/
    DotNetNuke.Services.Mail.Mail.SendMail(strFrom, strTo, strCC, strBCC, DotNetNuke.Services.Mail.MailPriority.Normal, strSubject, DotNetNuke.Services.Mail.MailFormat.Html, System.Text.Encoding.UTF8, strBody, "",
    strSMTP, hostSettings["SMTPAuthentication"], hostSettings["SMTPUsername"], hostSettings["SMTPPassword"]);
}

This is the example on how to use it:

SendMail("from@example.com", "to@example.com", "", "", "Subject goes here", "Email content goes here");

Make sure the SMTP settings have already been setup, because the function will read the settings from SMTP Details in the Host Settings section.

Just for your reference, you can use this free smtp test tool to test if the login details supplied are valid.

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

How to change copyright text in DNN?

In this article, I am going to show you how to change the copyright text in DNN. Usually, a copyright text is located under the footer of the site template.