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.