Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Personalization Subject Override results in (no subject) #428

Closed
willfolsom opened this issue Apr 1, 2021 · 5 comments
Closed

Personalization Subject Override results in (no subject) #428

willfolsom opened this issue Apr 1, 2021 · 5 comments
Labels
type: getting started question while getting started

Comments

@willfolsom
Copy link

willfolsom commented Apr 1, 2021

Any current known issues with setting the subject of a personalization?

personalization.Subject = "This should override the subject!"
newV3Mail.AddPersonalizations(personalization)

I'm getting an email with no subject. The template has an empty subject field. Everything else works as expected.

Screen Shot 2021-03-31 at 11 03 46 PM

This does not resolve it either.

newV3Mail.Subject = "OVERRIDE!"

I saw a previous issue where the answer seemed to be setting the subject in the template, which I'm ok with doing to an extent, but I definitely have the use case for this (i.e. using same template with a custom message body (working), and a dynamic subjects like "Thank You for Paying Invoice #123" or even "Hello, [cutomer name]!").

Thanks!

@JenniferMah
Copy link
Contributor

Hi @willfolsom,
Based on the two lines of code you provided it looks like you are setting the subject correctly. Can you include the rest of your code that you are using to send email with Sendgrid-go? Have you had a chance to try out the code sample for sending a personalization email?

@JenniferMah JenniferMah added status: waiting for feedback waiting for feedback from the submitter type: getting started question while getting started labels Apr 7, 2021
@willfolsom
Copy link
Author

Yes I've tried the snippet. Here is my implementation.

func (sgi *SendGridInteractor) SendSendGridEmail(emailInfo SendGridEmailInfo) error {
	newV3Mail := mail.NewV3Mail()

	newV3Mail.SetFrom(mail.NewEmail(sgi.config.DefaultFromName, sgi.config.DefaultFromEmail))

	if emailInfo.TemplateId == "" {
		emailInfo.TemplateId = BaseTemplateWithMessageBodyId
	}

	newV3Mail.SetTemplateID(emailInfo.TemplateId)

	personalization := mail.NewPersonalization()
	tos := []*mail.Email{
		mail.NewEmail(emailInfo.ToName, emailInfo.ToEmail),
	}
	personalization.AddTos(tos...)

	for _, element := range *emailInfo.MessageBodyValues {
		personalization.SetDynamicTemplateData(element.Key, element.Value)
	}

	if emailInfo.Subject == "" {
		emailInfo.Subject = DefaultEmailSubject
	}

	// The subject can be overridden here, otherwise it uses the template subject.
	// Currently getting emails with (no subject) if it's overridden, but I've asked about this on the repo.
	// This doesn't resolve it either: --> newV3Mail.Subject = "OVERRIDE!"
	personalization.Subject = emailInfo.Subject
	newV3Mail.AddPersonalizations(personalization)

	request := sendgrid.GetRequest(sgi.config.SecretKey, sgi.config.Endpoint, sgi.config.Host)
	request.Method = "POST"
	request.Body = mail.GetRequestBody(newV3Mail)

	if err := sgi.port.SendSendGridRequest(&request); err != nil {
		return err
	}

	return nil
}

@willfolsom
Copy link
Author

@JenniferMah Any update?

@childish-sambino
Copy link
Contributor

From the API docs for the templateId param:

An email template ID. A template that contains a subject and content — either text or html — will override any subject and content values specified at the personalizations or message level.

Based on this, there is an API limitation where the template's subject/content will always win out.

@willfolsom
Copy link
Author

@childish-sambino That is unfortunate. Maybe in the future this will be allowed. I have direct use cases for it.

@childish-sambino childish-sambino removed the status: waiting for feedback waiting for feedback from the submitter label Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: getting started question while getting started
Projects
None yet
Development

No branches or pull requests

3 participants