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

smtpapi substitutions not registering for multiple emails #192

Closed
tyrw opened this issue Oct 8, 2015 · 8 comments
Closed

smtpapi substitutions not registering for multiple emails #192

tyrw opened this issue Oct 8, 2015 · 8 comments

Comments

@tyrw
Copy link

tyrw commented Oct 8, 2015

When I send an email with substitutions and add multiple recipients via successive addTo definitions, only the first recipient sees the substitutions. Subsequent recipients see blanks where the substitutions should go.

email = new sendgrid.Email {
  from:     'order-confirmation@mysite.com'
  fromname: 'My site'
  replyto:  'support@mysite.com'
  subject:  'Foobar'
}
email.addTo order.email
email.addTo 'another@mysite.com'

email.addSubstitution '-greetings-', 'Howdy'
...

In this case, the recipient at order.email would receive the email exactly as it is intended (with Howdy substituted for -greetings-), while the recipient at another@mysite.com gets the same email, but with the -greetings- simply removed.

This also happens when I do bcc

Am I missing some setting that will apply the substitutions to all versions of the email?

@tyrw
Copy link
Author

tyrw commented Oct 8, 2015

This can be "solved" by expanding the substitution array to match the number of recipients (w lodash).

# Double the values for each key so that substitutions happen for both recipients
_.mapValues email.smtpapi.header.sub, (value) -> value.push value[0]

This feels really hackish though.

Is there a built-in function for doing this for n recipients, or some kind of flag that allows sending the same message to multiple recipients without them all being together on the to line?

@VictorAcatrinei
Copy link

Hi guys!
Do we have a better workaround regarding this? Thanks!

@jkrenge
Copy link

jkrenge commented Nov 11, 2015

+1

This can't be right. Why is sendgrid even sending out X emails? I obviously just want to send one email to multiple recipients.

@alist
Copy link

alist commented Jan 26, 2016

+1 this issue isn't necessarily to do with X-SMTPAPI

the homepage says Web API parameters instead of the X-SMTPAPI header. What this means is that if you call addTo() multiple times for an email, ONE email will be sent with each email address visible to everyone.

I too am iterating through a list of recipients, to emulate BCC.

@leobudima
Copy link

+1, rather weird problem and it's been open for more than 6 months...

@thinkingserious
Copy link
Contributor

Hello Everyone,

Thanks for all the great feedback!

We have just completed a major redesign of our /mail/send endpoint: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html. With this new version, the SMTPAPI header functionality is no longer separate and it should be much easier to achieve more complicated email workflows.

A new version of this library that supports that endpoint is about to replace this version in a few weeks: https://github.com/sendgrid/sendgrid-nodejs/tree/v3beta, you can check out the helper for the new endpoint here: https://github.com/sendgrid/sendgrid-nodejs/tree/v3beta/lib/helpers/mail

If you have trouble with the new endpoint or library, please open a new issue. Thanks!

With Best Regards,

Elmer

@dipakinfrrd
Copy link

dipakinfrrd commented Jul 25, 2017

Hello i am using c# sendgrid api and want to send email where each recipient should be substituted with the correct substitution.It not working properly, i followed the above issue .
I am using template for send email.

var tos = new List
{
new EmailAddress
{
Email = "test1@xyz.com",

            },
            new EmailAddress
            {
                Email = "test2@xyz.com",

            }
        };

var contents = new List<Dictionary<string, string>>
{
new Dictionary<string, string>() {{ "[recipient_first_name]", "Dipak"}},
new Dictionary<string, string>() {{ "[recipient_first_name]", "DS"}},
new Dictionary<string, string>() {{ "[recipient_last_name]", "Sharma"}},
new Dictionary<string, string>() {{ "[recipient_last_name]", "Gmail"}}
};
var msg = MailHelper.CreateMultipleEmailsToMultipleRecipients(myMessage.From,
myMessage.Personalizations[0].Tos,
new List { "Registration", "Registration" },
string.Empty,
string.Empty,
contents
);

only [recipient_first_name] is getting substituted not the second one.

Requirement:

I want a link which should be substituted for the to,cc's and bcc's which will be different for each recipient in any of to,cc's,bcc's list.
Can we do that while sending only one mail.

@thinkingserious
Copy link
Contributor

Hi @dipakinfrrd,

This is the repo for our Node.js library, could you please post this issue here.

Thanks!

With Best Regards,

Elmer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants