Пример #1
0
        public static void Send(Player player, string fileName)
        {
            Task.Run(async() =>
            {
                byte[] data = File.ReadAllBytes(fileName);

                var api = new MandrillApi("1_xltjpipEzKbs51aUb2Nw");

                var from = new MandrillMailAddress("*****@*****.**", "Canon Middle East");
                var to   = new MandrillMailAddress(player.Email, player.FullName);

                var message = new MandrillMessage(from, to);

                message.ReplyTo = "*****@*****.**";

                message.Subject = "Unlock the scientist in you";
                message.Html    = "Share your GIF in social media using the hashtags #CanonME and #Think_Science";


                var attachment = new MandrillAttachment("image/gif", "animation.gif", data);
                message.Attachments.Add(attachment);

                var result = await api.Messages.SendAsync(message);
            });
        }
Пример #2
0
        protected virtual MandrillAttachment TransferToMandrillAttachment(MailAttachment attachment)
        {
            var mandrillAttachment = new MandrillAttachment {
                Name = attachment.FileName
            };

            if (!string.IsNullOrEmpty(attachment.FilePath))
            {
                mandrillAttachment.Content = File.ReadAllBytes(attachment.FilePath);
            }
            else if (attachment.Bytes != null)
            {
                mandrillAttachment.Content = attachment.Bytes;
            }
            else if (attachment.Stream != null)
            {
                mandrillAttachment.Content = StreamToBytes(attachment.Stream);
            }
            else
            {
                throw new Exception("Attachment content cannot be null.");
            }

            return(mandrillAttachment);
        }
Пример #3
0
        private MandrillEmailMessage LoadMandrillMessageFromMailMessage(MailMessage message)
        {
            MandrillEmailMessage mandrillMessage = new MandrillEmailMessage();

            mandrillMessage.subject = message.Subject;
            if (message.IsBodyHtml)
            {
                mandrillMessage.html = message.Body;
            }
            else
            {
                mandrillMessage.text = message.Body;
            }
            mandrillMessage.from_email = message.From.Address;
            mandrillMessage.from_name  = message.From.DisplayName;
            foreach (var recipient in message.To)
            {
                mandrillMessage.to.Add(new MandrillRecipient {
                    type = "to", email = recipient.Address, name = recipient.DisplayName
                });
            }
            foreach (var cc in message.CC)
            {
                mandrillMessage.to.Add(new MandrillRecipient {
                    type = "to", email = cc.Address, name = cc.DisplayName
                });
            }
            mandrillMessage.bcc_address = message.Bcc.Select(b => b.Address).FirstOrDefault();
            mandrillMessage.important   = message.Priority == MailPriority.High;
            mandrillMessage.track_opens = true;
            foreach (var attachment in message.Attachments)
            {
                var mandrillAttachment = new MandrillAttachment();
                mandrillAttachment.name    = attachment.Name;
                mandrillAttachment.type    = attachment.ContentType.MediaType;
                mandrillAttachment.content = Convert.ToBase64String(Utilities.ToByteArray(attachment.ContentStream));

                mandrillMessage.attachments.Add(mandrillAttachment);
            }

            return(mandrillMessage);
        }