How to set Sender Name When Sending Emails Using Code in Kentico

Tuan Nguyen asked on December 13, 2017 12:17

Hi Kentico Support Team,

I have an issue of how to set sender name while sending emails in Kentico I am using below code to send emails: EmailSender.SendEmail(email) where email is an instance of EmailMessage.

I tried all ways but no luck for me. It would be great if you can reply this ASAP. Thanks in advanced!

Tuan

Recent Answers


Daniel Maley answered on December 13, 2017 18:03

Hi,

Hopefully your "email" is of type EmailMessage. If that is the case you should be able to do the following:

EmailMessage email = new EmailMessage();
email.From = "SomeoneOne@gmail.com";
EmailSender.SendEmail(email)

Additionally, you can get an email template that you have defined in Kentico through the portal and use that to build the subject/from/to/body of your email message. If you have a "from" address defined in the template you can add that "from" address to the Email Message like this:

EmailTemplateInfo template = EmailTemplateProvider.GetEmailTemplate("Template Name", "CurrentSiteName");
EmailMessage email = new EmailMessage();
email.From = EmailHelper.GetSender(template, "defaultsender@gmail.com");
EmailSender.SendEmail(email)
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.