CPANEL/WHM: How to configure a domain to use Sendgrid SMTP

configure domain using sendgrid

Configuring a domain in cPanel/WHM to use SendGrid’s SMTP service enhances email deliverability and ensures reliable message delivery. Here’s a straightforward guide to set this up:

  1. Login to your WHM account using the root credentials
  2. Click on Service Configuration -> Exim Configuration Manger
  3. Click on the Advanced Editor tab as shown in the screenshot below
    exim configuration manager

  4. Find the section called Section: AUTH and paste the following into the text box, substituting in your SendGrid username and password:
    sendgrid_login:
    driver = plaintext
    public_name = LOGIN
    client_send = : <YourSendGridUsername> : <YourSendGridPassword>
    See my screenshot below:
    configure cpanel sendgrid smtp
  5. Find the section called Section: PREROUTERS paste the following in the textbox, substituting in your Domain name in the senders line:
    send_via_sendgrid:
    driver = manualroute
    domains = ! +local_domains
    senders = *@<YourDomainHere>
    transport = sendgrid_smtp
    route_list = "* smtp.sendgrid.net::587 byname"
    host_find_failed = defer
    See my screenshot below:

  6. Find the section called Section: TRANSPORTSTART and paste the following in the textbox:
    sendgrid_smtp:
    driver = smtp
    hosts = smtp.sendgrid.net
    hosts_require_auth = smtp.sendgrid.net
    hosts_require_tls = smtp.sendgrid.net
    See my screenshot below:
    cpanel sendgrid smtp

Important Considerations

  • API Key: Ensure you’ve generated a SendGrid API key with at least ‘Mail’ permissions. Replace YOUR_SENDGRID_API_KEY in the configuration with this key.
  • Domain-Specific Configuration: If you want only a specific domain to use SendGrid while others continue using the default SMTP, adjust the senders parameter in the Section: POSTMAILCOUNT configuration:iniCopyEditsenders = *@yourdomain.com Replace yourdomain.com with the desired domain.
  • Testing: After configuration, send a test email to confirm that emails are routing through SendGrid. Monitor /var/log/exim_mainlog for any errors:bashCopyEdittail -f /var/log/exim_mainlog

By following these steps, your cPanel/WHM server will route outgoing emails through SendGrid, enhancing deliverability and providing robust email management features.

See also  DORA Metrics Explained: Key to Faster and Reliable DevOps

FAQs

Why should I use SendGrid with cPanel/WHM?

A1: Integrating SendGrid improves email deliverability, offers advanced analytics, and reduces the chances of your emails being marked as spam.

Can I configure multiple domains to use SendGrid?

Yes, by specifying multiple domains in the senders parameter or using wildcards, you can route emails from multiple domains through SendGrid.

What if I encounter errors after configuration?

Check the Exim main log at /var/log/exim_mainlog for error messages. Ensure that your API key is correct and that your server can connect to smtp.sendgrid.net on port 587.

By setting up SendGrid as your SMTP relay in cPanel/WHM, you can achieve more reliable and efficient email delivery for your domains.

Photo of author
As Editor in Chief of HeatWare.net, Sood draws on over 20 years in Software Engineering to offer helpful tutorials and tips for MySQL, PostgreSQL, PHP, and everyday OS issues. Backed by hands-on work and real code examples, Sood breaks down Windows, macOS, and Linux so both beginners and power-users can learn valuable insights. For questions or feedback, he can be reached at sood@heatware.net.