What are Sendgrid Email Categories
Creating categories for different kinds of emails sent through sendgrid is quite beneficial. It allows you to track emails based on each category i.e. it allows you to tag your emails by topics.
e.g. it would be nice to know
- how many user registration emails actually were delivered,
- how many people requested password resets, etc
For instance emails sent through wordpress can be categorised as
- User Registration
- Password Reset
- Newsletter, etc
How to add Sendgrid categories
As per the sendgrid documentation
You can add categories to the X-SMTPAPI header of the emails you send via SendGrid. This will allow you to track emails based on your own categorization system.
In case of wordpress emails here are the steps to follow
- Install the WordPress Sengrid plugin: Since the version 1.6.9 this plugin allows to add categories in the email headers.
- add the category headers to the wp_mail function as shown below
How to add category headers to the wp_mail function
$headers = 'categories: Newsletter, may2015';
wp_mail($username, $subject, $message, $headers);
The above headers can be added to your custom plugins where you define your own wp_mail function.
However in case of wordpress internal emails e.g. User Registration Confirmation email you would need to first customise that email to be able to add the required headers. For instance here is a nice link which shows how to customise User Registration Confirmation Emails
Sendgrid Category statistics
Once the required headers are added sengrid can shows statistics based on each sendgrid categories as shown below