This article will provide you with short example of sending e-mails using the code.
You can send an email programmatically through our API in the following way:
CMS.EmailEngine.EmailMessage em = new CMS.EmailEngine.EmailMessage();
em.EmailFormat = CMS.EmailEngine.EmailFormatEnum.Html;
em.From = "from@mail.com";
em.Recipients = "to@mail.com";
em.Subject = "Subject";
em.Body = "body of email";
CMS.EmailEngine.EmailSender.SendEmail("site_name", em);
Please make sure you have SMTP server specified in site settings for e-mails being sent properly.
There are two basic variations of
SendEmail method:
CMS.EmailEngine.EmailSender.SendEmail(em);
//or
CMS.EmailEngine.EmailSender.SendEmail("site_name", em);
//you can use CMS.CMSHelper.CMSContext.CurrentSiteName for site name
The first one sends e-mail using global settings, whilest the second one sends e-mail using settings for specified site. If you use the first option and it doesn't work for you, it can be caused by SMTP settings specified only for appropriate site - not globally.
See also:
How to send an email using the email template
Applies to:
Kentico CMS all versions
Created on
11/24/2008 6:52:55 AM in
Newsletters and E-mail