def test_all_options(self): send_at = datetime.now().replace(microsecond=0) + timedelta(minutes=2) message = AnymailMessage( subject="Anymail all-options integration test FILES", body="This is the text body", from_email="Test From <*****@*****.**>", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, metadata={"meta1": "simple string", "meta2": 2}, send_at=send_at, tags=["tag 1", "tag 2"], track_clicks=True, track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'queued'}) # SendGrid always queues
def test_all_options(self): message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email="Test From <*****@*****.**>", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, # no metadata, send_at, track_clicks support tags=["tag 1"], # max one tag track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertTrue( message.anymail_status.status.issubset({'queued', 'sent'}))
def test_all_options(self): message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email="Test From <*****@*****.**>", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, # no metadata, send_at, track_clicks support tags=["tag 1"], # max one tag track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertTrue(message.anymail_status.status.issubset({'queued', 'sent'}))
def test_all_options(self): message = AnymailMessage( subject="Anymail Postmark all-options integration test", body="This is the text body", # Postmark accepts multiple from_email addresses, but truncates to the first on their end from_email="Test From <*****@*****.**>, [email protected]", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, # no metadata, send_at, track_clicks support tags=["tag 1"], # max one tag track_opens=True, track_clicks=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'sent'})
def test_all_options(self): message = AnymailMessage( subject="Anymail Mailjet all-options integration test", body="This is the text body", from_email='"Test Sender, Inc." <*****@*****.**>', to=[ '*****@*****.**', '"Recipient, 2nd" <*****@*****.**>' ], cc=['*****@*****.**', 'Copy 2 <*****@*****.**>'], bcc=[ '*****@*****.**', 'Blind Copy 2 <*****@*****.**>' ], reply_to=['"Reply, To" <*****@*****.**>' ], # Mailjet only supports single reply_to headers={"X-Anymail-Test": "value"}, metadata={ "meta1": "simple string", "meta2": 2 }, tags=["tag 1"], # Mailjet only allows a single tag track_clicks=True, track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'sent'})
def test_all_options(self): send_at = datetime.now() + timedelta(minutes=2) message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email="Test From <*****@*****.**>", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, metadata={"meta1": "simple string", "meta2": 2}, send_at=send_at, tags=["tag 1"], # SparkPost only supports single tags track_clicks=True, track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'queued'}) # SparkPost always queues
def test_all_options(self): send_at = datetime.now().replace(microsecond=0) + timedelta(minutes=2) message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email='"Test From, with comma" <*****@*****.**>', to=["*****@*****.**", '"Recipient 2, OK?" <*****@*****.**>'], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=['"Reply, with comma" <*****@*****.**>'], # v3 only supports single reply-to headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3}, metadata={"meta1": "simple string", "meta2": 2}, send_at=send_at, tags=["tag 1", "tag 2"], track_clicks=True, track_opens=True, # esp_extra={'asm': {'group_id': 1}}, # this breaks activity feed if you don't have an asm group ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'queued'}) # SendGrid always queues
def test_all_options(self): message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email='"Test Sender, Inc." <*****@*****.**>', to=['*****@*****.**', '"Recipient, 2nd" <*****@*****.**>'], cc=['*****@*****.**', 'Copy 2 <*****@*****.**>'], bcc=['*****@*****.**', 'Blind Copy 2 <*****@*****.**>'], reply_to=['*****@*****.**', '"Reply, 2nd" <*****@*****.**>'], headers={"X-Anymail-Test": "value"}, metadata={"meta1": "simple string", "meta2": 2}, tags=["tag 1"], # Mailjet only allows a single tag track_clicks=True, track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'sent'})
def test_all_options(self): message = AnymailMessage( subject="Anymail Amazon SES all-options integration test", body="This is the text body", from_email='"Test From" <*****@*****.**>', to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, metadata={"meta1": "simple_string", "meta2": 2}, tags=["Re-engagement", "Cohort 12/2017"], ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.attach_alternative( "Amazon SES SendRawEmail actually supports multiple alternative parts", "text/x-note-for-email-geeks") message.send() self.assertEqual(message.anymail_status.status, {'queued'})
def test_all_options(self): send_at = datetime.now().replace(microsecond=0) + timedelta(minutes=2) message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email='"Test From, with comma" <*****@*****.**>', to=["*****@*****.**", '"Recipient 2, OK?" <*****@*****.**>'], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=['"Reply, with comma" <*****@*****.**>'], # v3 only supports single reply-to headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3}, metadata={"meta1": "simple string", "meta2": 2}, send_at=send_at, tags=["tag 1", "tag 2"], track_clicks=True, track_opens=True, # esp_extra={'asm': {'group_id': 1}}, # this breaks activity feed if you don't have an asm group ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,Amy Lina", "text/csv") cid = message.attach_inline_image_file(sample_image_path()) message.attach_alternative( "<p><b>HTML:</b> with <a href='http://example.com'>link</a>" "and image: <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'queued'}) # SendGrid always queues
def test_all_options(self): send_at = datetime.now().replace(microsecond=0) + timedelta(minutes=2) send_at_timestamp = mktime(send_at.timetuple()) # python3: send_at.timestamp() message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email="Test From <*****@*****.**>", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, metadata={"meta1": "simple string", "meta2": 2}, send_at=send_at, tags=["tag 1", "tag 2"], track_clicks=False, track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,3", "text/csv") cid = message.attach_inline_image_file(sample_image_path(), domain=MAILGUN_TEST_DOMAIN) message.attach_alternative( "<div>This is the <i>html</i> body <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'queued'}) # Mailgun always queues message_id = message.anymail_status.message_id events = self.fetch_mailgun_events(message_id, event="accepted") if events is None: self.skipTest("No Mailgun 'accepted' event after 30sec -- can't complete this test") return event = events.pop() self.assertCountEqual(event["tags"], ["tag 1", "tag 2"]) # don't care about order self.assertEqual(event["user-variables"], {"meta1": "simple string", "meta2": "2"}) # all metadata values become strings self.assertEqual(event["message"]["scheduled-for"], send_at_timestamp) self.assertCountEqual(event["message"]["recipients"], ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**']) # don't care about order headers = event["message"]["headers"] self.assertEqual(headers["from"], "Test From <*****@*****.**>") self.assertEqual(headers["to"], "[email protected], Recipient 2 <*****@*****.**>") self.assertEqual(headers["subject"], "Anymail all-options integration test") attachments = event["message"]["attachments"] self.assertEqual(len(attachments), 2) # because inline image shouldn't be an attachment self.assertEqual(attachments[0]["filename"], "attachment1.txt") self.assertEqual(attachments[0]["content-type"], "text/plain") self.assertEqual(attachments[1]["filename"], "attachment2.csv") self.assertEqual(attachments[1]["content-type"], "text/csv")
def test_all_options(self): send_at = datetime.now().replace(microsecond=0) + timedelta(minutes=2) send_at_timestamp = mktime(send_at.timetuple()) # python3: send_at.timestamp() message = AnymailMessage( subject="Anymail all-options integration test", body="This is the text body", from_email="Test From <*****@*****.**>", to=["*****@*****.**", "Recipient 2 <*****@*****.**>"], cc=["*****@*****.**", "Copy 2 <*****@*****.**>"], bcc=["*****@*****.**", "Blind Copy 2 <*****@*****.**>"], reply_to=["*****@*****.**", "Reply 2 <*****@*****.**>"], headers={"X-Anymail-Test": "value"}, metadata={"meta1": "simple string", "meta2": 2}, send_at=send_at, tags=["tag 1", "tag 2"], track_clicks=False, track_opens=True, ) message.attach("attachment1.txt", "Here is some\ntext for you", "text/plain") message.attach("attachment2.csv", "ID,Name\n1,3", "text/csv") cid = message.attach_inline_image_file(sample_image_path(), domain=MAILGUN_TEST_DOMAIN) message.attach_alternative( "<div>This is the <i>html</i> body <img src='cid:%s'></div>" % cid, "text/html") message.send() self.assertEqual(message.anymail_status.status, {'queued'}) # Mailgun always queues message_id = message.anymail_status.message_id events = self.fetch_mailgun_events(message_id, event="accepted") if events is None: self.skipTest("No Mailgun 'accepted' event after 30sec -- can't complete this test") return event = events.pop() self.assertCountEqual(event["tags"], ["tag 1", "tag 2"]) # don't care about order self.assertEqual(event["user-variables"], {"meta1": "simple string", "meta2": "2"}) # all metadata values become strings self.assertEqual(event["message"]["scheduled-for"], send_at_timestamp) self.assertCountEqual(event["message"]["recipients"], ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**']) # don't care about order headers = event["message"]["headers"] self.assertEqual(headers["from"], "Test From <*****@*****.**>") self.assertEqual(headers["to"], "[email protected], Recipient 2 <*****@*****.**>") self.assertEqual(headers["subject"], "Anymail all-options integration test") attachments = event["message"]["attachments"] self.assertEqual(len(attachments), 2) # because inline image shouldn't be an attachment self.assertEqual(attachments[0]["filename"], "attachment1.txt") self.assertEqual(attachments[0]["content-type"], "text/plain") self.assertEqual(attachments[1]["filename"], "attachment2.csv") self.assertEqual(attachments[1]["content-type"], "text/csv")