Sending emails from third-party

Mike Brown asked on February 23, 2015 22:15

I have a SendGrid account and I wanted to use their API directly instead of setting up the SMTP server settings.

What code needs to be modified? Would I change the CMSModules_EmailQueue_SendEmail.SendEmail() method?

Correct Answer

Bryan Soltis answered on February 24, 2015 16:20

I agree with Brenden. Overriding the "SendEmailInternal" event is definitely the way to go and how to put your custom code in a nice, packaged area. This will ensure you don't break any upgrade paths. You can pout whatever code you want in the custom email provider.

https://docs.kentico.com/display/K82/Custom+Email+provider+example

  • Bryan
1 votesVote for this answer Unmark Correct answer

Recent Answers


Virgil Carroll answered on February 24, 2015 00:16

We use the same thing on our Kentico site. Actually found it easier to setup a local SMTP server and use that in Kentico, from there you forward to SendGrid. Easy to implement and not modifying any of the core code.

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 24, 2015 07:45

If you don't go with what Virgil suggested, I'd suggest NOT modifying that code you mentioned. Rather create a global handler and override anytime a mail message is sent. This way no matter where the email is sent from, it will always be captured and use the code you write integrating with SendGrid.

2 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on February 24, 2015 16:48

Guess I would disagree with both of you, why do a code solution when there is a non-code solution to use? Sorry my mind doesn't always fall along the programmer mindset. If you want something that is truly upgradeable and never have to worry it breaking across upgrade paths then take the custom code completely out of the equation. Where your methods may work and maybe upgradeable for the long term, after seeing how the internal API was changed from v7 to v8 (splitting of DLLs and such) I would always stray to a non-programmatic solution. It reduces a dependency that in my mind is not necessary.

Just my two cents.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 24, 2015 17:08

I'm not disagreeing with you at all Virgil, your solution works. What I'm stating is if that simple solution won't work for the OP and he want's to do some other type of interaction with the SendGrid API before or during the send of the email (which it sounds like), I suggested to NOT modify that user control the OP was talking about but take a more global approach and override the methods already in place.

0 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on February 24, 2015 17:12

Just adding some friendly debate to the mix :) All is good.

1 votesVote for this answer Mark as a Correct answer

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