Ejemplo n.º 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);
            });
        }
Ejemplo n.º 2
0
        public async Task <string> SendViaMandrill(string subject, string htmlBody, List <string> toEmail, List <string> ccEmail = null, List <string> bccEmail = null, List <MandrillAttachment> attachments = null, bool isPreserve = true, string fromEmail = "", string fromName = "")
        {
            var api = new MandrillApi(APIKey);

            string defaultEmail = configuration["EmailSettings:FromEmail"];
            string defaultName  = configuration["EmailSettings:Name"];

            var message = new MandrillMessage
            {
                FromEmail = fromEmail.ConvertNullOrEmptyTo(defaultEmail),
                FromName  = fromName.ConvertNullOrEmptyTo(defaultName)
            };

            message.Html    = htmlBody;
            message.Subject = subject;
            var recipients = new List <MandrillMailAddress>();

            foreach (var email in toEmail)
            {
                if (!string.IsNullOrEmpty(email))
                {
                    var to = new MandrillMailAddress
                    {
                        Type  = MandrillMailAddressType.To,
                        Email = email
                    };
                    recipients.Add(to);
                }
            }

            if (ccEmail != null && ccEmail.Any())
            {
                foreach (var e in ccEmail)
                {
                    if (!string.IsNullOrEmpty(e))
                    {
                        var cc = new MandrillMailAddress
                        {
                            Type  = MandrillMailAddressType.Cc,
                            Email = e
                        };
                        recipients.Add(cc);
                    }
                }
            }

            if (bccEmail != null && bccEmail.Any())
            {
                foreach (var bcc in bccEmail)
                {
                    if (!string.IsNullOrEmpty(bcc))
                    {
                        recipients.Add(new MandrillMailAddress
                        {
                            Type  = MandrillMailAddressType.Bcc,
                            Email = bcc
                        });
                    }
                }
            }

            message.PreserveRecipients = isPreserve;
            message.To = recipients;

            if (attachments != null && attachments.Any())
            {
                message.Attachments = attachments;
            }

            var result = await api.Messages.SendAsync(message);

            var statuses = (result != null && result.Any()) ? result.Select(x => x.Status).ToList() : null;

            return(statuses != null?string.Join(',', statuses) : "Unknown");
        }