How to customize unsubscribe link in sendgrid mail
To customize the unsubscribe link in SendGrid Mail, you can follow these steps:
Method 1: Using the SendGrid UI
- Log in to your SendGrid account and navigate to the Settings tab.
- Click on Mail Settings and then select Unsubscribe from the dropdown menu.
- In the Unsubscribe Settings section, click on the Edit button next to Unsubscribe Link.
- In the Unsubscribe Link field, enter the custom URL you want to use for the unsubscribe link. You can use SendGrid's default unsubscribe link or create your own custom link.
- Click Save to save your changes.
Method 2: Using the SendGrid API
- Use the SendGrid API to update the unsubscribe link for your email campaign. You can do this by making a PUT request to the
/v3/mail/settings/unsubscribe
endpoint. - In the request body, include the
unsubscribe_link
parameter with the custom URL you want to use for the unsubscribe link. - Here's an example of what the request body might look like:
{ "unsubscribe_link": "https://example.com/unsubscribe" }
- Make the request to the SendGrid API to update the unsubscribe link.
Method 3: Using a SendGrid Template
- Create a SendGrid template for your email campaign.
- In the template, use the
{{ unsubscribe_link }}
placeholder to insert the unsubscribe link. - When you send the email campaign, SendGrid will replace the placeholder with the custom unsubscribe link you specified in the template.
Tips and Considerations
- When customizing the unsubscribe link, make sure to include the
?unsub=true
parameter in the URL to indicate that it's an unsubscribe link. - You can also include additional parameters in the unsubscribe link, such as
?list=example
to specify the list that the user is unsubscribing from. - Make sure to test your custom unsubscribe link to ensure that it's working correctly and that users are being unsubscribed from your email list as expected.
- If you're using a custom unsubscribe link, you'll need to handle the unsubscribe request on your own server-side code. SendGrid will send a request to your server with the
X-SMTPAPI
header containing the unsubscribe request.