using System; using System.Collections.Generic; using TNZAPI.Messaging.Objects; using TNZAPI.Messaging.Send; using TNZAPI.Messaging.Functions; namespace TNZEmailAdvanced { class Program { static void Main(string[] args) { #region Declarations const string sender = "YOUR_EMAIL_ADDRESS"; const string api_key = "YOUR_API_KEY"; const string reference = "Test Email - Advanced version"; const string recipient1 = "email1@test.com"; const string recipient2 = "email2@test.com"; const string recipient3 = "email3@test.com"; const string recipient4 = "email4@test.com"; const string file1 = "c:\\file1.pdf"; const string file2 = "c:\\file2.pdf"; const string file3 = "c:\\file3.pdf"; const string file4 = "c:\\file4.pdf"; const string smtp_from = "email@test.com"; const string from_name = "Test Email"; const string from_email = "from@test.com"; const string reply_to = "reply@test.com"; const string subject = "TNZ API Email - Advanced"; const string message_plain = "Test Email Body"; const string message_html = "<html><body><p>This is <b>Test message body</b>. Thank you so much!</p></body></html>"; #endregion Declarations Email EmailMessage = new Email(sender, api_key); #region Add Recipients // // Add Recipient Method 1 - AddRecipient(string recipient); // EmailMessage.AddRecipient(recipient1); // // Add Recipient Method 2 - AddRecipient(new Recipient()) // Recipient recipient = new Recipient(); recipient.EmailAddress = recipient2; // Recipient recipient.CompanyName = "Test Company"; // Company Name recipient.Attention = "Test Recipient 2"; // Attention recipient.Custom1 = "Custom1"; // Custom1 recipient.Custom2 = "Custom2"; // Custom2 recipient.Custom3 = "Custom3"; // Custom3 recipient.Custom4 = "Custom4"; // Custom4 recipient.Custom5 = "Custom5"; // Custom5 EmailMessage.AddRecipient(recipient); // // Add Recipient Method 3 - AddRecipients(new List<Recipient>()); using simple destination // List<Recipient> recipients = new List<Recipient>(); recipients.Add(new Recipient(recipient3)); // // Add Recipient Method 4 - AddRecipients(new List<Recipient>()) using Recipient objects // recipients.Add(new Recipient( recipient4, // Recipient "Test Company", // Company Name "Test Recipient 3", // Attention "Custom1", // Custom1 "Custom2", // Custom2 "Custom3", // Custom3 "Custom4", // Custom4 "Custom5" // Custom5 )); EmailMessage.AddRecipients(recipients); #endregion Add Recipients #region Add Attachments // // Add Attachment Method 1 - AddAttachment(file_location); // EmailMessage.AddAttachment(file1); // // Add Attachment Method 2 - AddAttachment(new Attachment()); // Attachment attachment = new Attachment(); attachment.FileName = FileHandlers.GetFileName(file2); attachment.FileContent = FileHandlers.GetFileContents(file2); EmailMessage.AddAttachment(attachment); // // Add Attachment Method 3 - AddAttachments(new List<Attachment>()) using simple file locations // List<Attachment> attachments = new List<Attachment>(); attachments.Add(new Attachment(file3)); // // Add Attachment Method 4 - AddAttachments(new List<Attachment>()) using Attachment objects // attachments.Add(new Attachment( FileHandlers.GetFileName(file4), FileHandlers.GetFileContents(file4) )); EmailMessage.AddAttachments(attachments); #endregion Add Attachments #region Set SMTP Headers // Set email sender EmailMessage.SetEmailFrom( smtp_from, from_name, from_email, reply_to ); #endregion Set SMTP Headers MessageResult response = EmailMessage.SendMessage( subject, //Subject message_plain, //MessagePlain message_html, //MessageHTML "", //MessageID reference, //Reference new DateTime(), //SendTime "New Zealand", //Timezone "", //SubAccount "", //Department "" //ChargeCode ); if (response.Result == MessageResult.ResultCode.Success) { Console.WriteLine("Success - "+response.MessageID); } else { Console.WriteLine("Error - " + response.ErrorMessage); } } } }