Bulk email Sending using SendGrid with Cc as common

Viewed 192

I'm new to SendGrid. I need to send Bulk emails using SendGrid. I referred github for sample example like below it was good to get understood about how to use it. reference link here. Now, I had installed gem 'sendgrid-ruby' and configured using SendGrid credentials and tried below sample code with custom details on console.

  mail = SendGrid::Mail.new
  mail.from = Email.new(email: 'test@example.com')
  mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
  personalization = Personalization.new
  personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
  personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
  personalization.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
  personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
  personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
  personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
  personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
  personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
  personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
  personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
  personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
  personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
  personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
  personalization.send_at = 1443636843
  mail.add_personalization(personalization)

  personalization2 = Personalization.new
  personalization2.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
  personalization2.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
  personalization2.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
  personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
  personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
  personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
  personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
  personalization2.add_header(Header.new(key: 'X-Test', value: 'True'))
  personalization2.add_header(Header.new(key: 'X-Mock', value: 'False'))
  personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
  personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
  personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
  personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
  personalization2.send_at = 1443636843
  mail.add_personalization(personalization2)

  mail.add_content(Content.new(type: 'text/plain', value: 'some text here'))
  mail.add_content(Content.new(type: 'text/html', value: '<html><body>some text here</body></html>'))
@client.mail._("send").post(request_body: mail.to_json)

Here i need to send array of Cc's as common, instead of adding inside all personalisations. I tried with adding single personalisation and all emails inside to_emails list and added cc. I received mail with list of all other to emails list. To avoid this i need to go for different personalisation. Any idea for adding cc as common ?

0 Answers
Related