Send Marketing Emails Through SendGrid While Sending Race Results Through IIS
Send Marketing Emails Through SendGrid While Sending Race Results Through IIS
A track may want to have only their marketing e-mails sent through SendGrid while all other e-mails such as race results sent through IIS. The reason a track may want this is because SendGrid charges for a certain amount of e-mails per month and if all race results are set to send through SendGrid, the cost rises.
There are two ways to do this, you can use either the customer's SendGrid username/password, or use a generated API key.
Username/password method:
1. Make sure the track has a SendGrid account and have them provide their SendGrid username (may be different from their e-mail) and their password.
2. Make sure IIS is NOT set to relay to SendGrid. Clubspeed will handle relaying to SendGrid once you set up the SMTPMarketing settings in the next step. If IIS is set to relay to SendGrid, race results will be sent to SendGrid. Follow the steps in this article to use as a reference: Troubleshooting SMTP
3. Open SQL > dbo.ControlPanel > scroll down to the MainEngine settings that begin with "SMTPMarketing" (NOT "SMTPServer").

4. Input the following values for each associated setting:
SMTPMarketing: smtp.sendgrid.net
SMTPMarketingServerAuthenticationPassword: *insert customer's SendGrid password here*
SMTPMarketingServerAuthenticationUserName: *insert customer's SendGrid password here* (again, username may be different from their e-mail.)
SMTPMarketingServerEncryptionType: ssl
SMTPMarketingServerPort: Set to 25 if you're sure that port is open and their ISP allows traffic from it. You can test this out by opening command prompt and entering the command:
If you get a 220 response, the port is open. If not, try port 587 as an alternative to 25.
SMTPMarketingServerUseAuthentiation: 1 (SendGrid does not accept unauthenticated requests so this won't work if it's set to 0).
SMTPMarketingServerUseSSL: 1 (still works if you set to 0, but encrypted e-mails are always a better idea!)
Your final settings should look like this, make sure the MainEngine settings that start with "SMTPServer" are set to the defaults as well. (you may need to adjust the port number accordingly if the track's ISP is blocking port 25).

5. Execute the changes in SQL and restart Main Engine. You should be all done! You can have the customer test it out by sending a few marketing and race result e-mails. The customer should be able to see their e-mail activity at the SendGrid dashboard, but it takes a while to update sometimes. If the customer reports they are not seeing any activity on their dashboard, have them go into the "Activity" tab on SendGrid.

API Key/Password Method:
To avoid passing credentials in plaintext or if the customer does not feel comfortable with providing their SendGrid username and password, we can have them create an API key and we can configure it appropriately in SQL.
1. Follow the same steps as the username/password method until you get to Step 3. The only settings we will need to change in Step 3 are: SMTPMarketingServerAuthenticationPassword, SMTPMarketingServerAuthenticationUserName, and SMTPMarketingServerPort.
2. Provide the customer this link: SendGrid API Keys and have them create an API key. The API key needs to at least have the "Mail" permissions set in order for this to work.

3. Once the API key is created, have them provide it to you and replace the "SMTPMarketingServerAuthenticationPassword" setting with it. For the "SMTPMarketingServerAuthenticationUserName" setting, use "apikey". For the "SMTPMarketingServerPort" setting, use port 587, not 25.
SendGrid SMTP API documentation explaining this: SMTP API Integration
4. Execute the changes in SQL and restart Main Engine! Have them test it out.
Troubleshooting:
Race results are going through but marketing e-mails are not: Verify all the SMTPMarketing settings in SQL. Remember, the username for the SendGrid account has to be used, not the e-mail. They may be different depending on how they set it up.
Marketing e-mails are going through but race results are not: Verify the SMTP server configuration in IIS. Make sure IIS is NOT set to relay to SendGrid. Follow the "Troubleshooting SMTP" ZD article linked above.
No e-mails are going through: Were they able to send e-mails in the first place before implementing this? Follow the "Troubleshooting SMTP" ZD article linked above. Also, verify that port 25 is open and their ISP allows traffic from it. Try using port 587 as an alternative.
API key method is not working: Make sure that the generated API key has full access to at least the "Mail Send" and "Mail Settings" endpoints. Also, if you have the SQL settings "SMTPMarketingServerUseSSL" and "SMTPMarketingServerUseAuthentiation" set to "1", the API key may need full access to the "Security" and "Sender Authentication" endpoints as well.