Sparkpost API - Multiple people in the TO: and BCC:
Referencing https://gist.github.com/trouttco/5eafb0d7b36d49ad2e4e
This is your standard way to send emails to people, however, emails only gets sent to each person individually.
def bigcommerce_report(time_span, monthly_revenue, yearly_revenue, attachment)
tag = action_name
to = ['[email protected]', '[email protected]', '[email protected]']
data_hash = {recipients:[]}
to.each { |recip_email| data_hash[:recipients] << { tags:[tag], address:{email:recip_email}} }
@time_span = time_span
@monthly_revenue = monthly_revenue
@yearly_revenue = yearly_revenue
send_mail(
to: to,
subject: "POWr Rev Share for #{time_span}",
attachments: attachment,
data: data_hash,
file_type: 'csv'
)
end
To make sure everyone is included in the TO: clause, you need to add a header_to condition in the address with the emails as a comma separated string:
def bigcommerce_report(time_span, monthly_revenue, yearly_revenue, attachment)
tag = action_name
to = ['[email protected]', '[email protected]', '[email protected]']
data_hash = {recipients:[]}
to.each { |recip_email| data_hash[:recipients] << {tags:[tag],address:{email:recip_email, header_to:to.join(',')}} }
@time_span = time_span
@monthly_revenue = monthly_revenue
@yearly_revenue = yearly_revenue
send_mail(
to: to,
subject: "POWr Rev Share for #{time_span}",
attachments: attachment,
data: data_hash,
file_type: 'csv'
)
end
To BCC a person, just remove them from the header_to. Note that this doesn't actually throw the email in the BCC field, it just sends the email without including them in the TO:
def bigcommerce_report(time_span, monthly_revenue, yearly_revenue, attachment)
tag = action_name
to = ['[email protected]', '[email protected]', '[email protected]']
data_hash = {recipients:[]}
to.each { |recip_email| data_hash[:recipients] << {tags:[tag],address:{email:recip_email, header_to: (to - ['[email protected]']).join(',')}} }
@time_span = time_span
@monthly_revenue = monthly_revenue
@yearly_revenue = yearly_revenue
send_mail(
to: to,
subject: "POWr Rev Share for #{time_span}",
attachments: attachment,
data: data_hash,
file_type: 'csv'
)
end