You do not need custom code, just configure a new Email Account, with the correct SMTP details
Set the following:
Email address - whatever you want Email display name - whatever you want Host - smtp.sendgrid.net Port - 587 User - your sendgrid user name Password - your sendgrid password SSL - false Use default credentials - false
I got it now. You need to set an SMTP relay and fill in this:
Email address: yourname@yourdomain Email display name: yourname Host: smtp.sendgrid.net Port: 587 User: apikey <-- Here the word apikey not the name for your key Password: generated key SSL: unchecked Use default credentials: unchecked