Ejemplo n.º 1
0
        public void sendContactRequestEmail(EmailRequestModel crModel)
        {
            string renderedHTML = EmailService.RenderRazorViewToString("~/Views/TestEmail/Index.cshtml", crModel);
            //email payload
            var ActivateCrEmail = new SendMessageRequest(new EmailMessage
            {
                To =
                    new List <EmailAddress> {
                    new EmailAddress {
                        Email = crModel.Email, Name = "Bringpro"
                    }
                },
                FromEmail = ConfigService.MandrillFromEmail,
                Html      = renderedHTML,
                Subject   = "Your bringpro input has been successfully submitted!"
            });
            //sets api key to api key stored in config file - makes easily changeable
            var api = new MandrillApi(ConfigService.MandrillApiKey);

            //Mandrill Requires functions to be set as async.
            //This line of code lets us run void functions asynchronously
            //Purpose - to match interface signatures with sendgrid interface
            //Will be in ALL Mandrill Functions
            Task.Run(async() => await api.SendMessage(ActivateCrEmail));
        }
Ejemplo n.º 2
0
    public async Task Should_Send_Email_Message_Without_Template()
    {
      // Setup
      string apiKey = ConfigurationManager.AppSettings["APIKey"];
      string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
      string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

      // Exercise
      var api = new MandrillApi(apiKey);

      List<EmailResult> result = await api.SendMessage(new SendMessageRequest(new EmailMessage
        {
          To =
            new List<EmailAddress> {new EmailAddress {Email = toEmail, Name = ""}},
          FromEmail = fromEmail,
          Subject = "Mandrill Integration Test",
          Html = "<strong>Example HTML</strong>",
          Text = "Example text"
        }));

      // Verify
      Assert.AreEqual(1, result.Count);
      Assert.AreEqual(toEmail, result.First().Email);
      Assert.AreEqual(EmailResultStatus.Sent, result.First().Status);
    }
Ejemplo n.º 3
0
        public void Scheduled_Message_Is_Rescheduled()
        {
            // Setup
            var    apiKey    = ConfigurationManager.AppSettings["APIKey"];
            string toEmail   = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var messages = api.SendMessage(new EmailMessage
            {
                to =
                    new List <EmailAddress> {
                    new EmailAddress {
                        email = toEmail, name = ""
                    }
                },
                from_email = fromEmail,
                subject    = "Mandrill Integration Test",
                html       = "<strong>Scheduled Email</strong>",
                text       = "Example text"
            }, DateTime.UtcNow.AddMinutes(5.0));

            var message = api.ListScheduledMessages().Find(s => s.Id == messages.First().Id);

            var rescheduled = api.RescheduleMessage(message.Id, message.SendAt.AddMinutes(5.0));

            //Verify
            Assert.Greater(rescheduled.SendAt, message.SendAt);

            //Tear down
            api.CancelScheduledMessage(rescheduled.Id);
        }
Ejemplo n.º 4
0
        public void Message_Without_Template_Is_Sent()
        {
            // Setup
            var apiKey = ConfigurationManager.AppSettings["APIKey"];
            string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var result = api.SendMessage(new EmailMessage
            {
                to =
                    new List<EmailAddress> { new EmailAddress { email = toEmail, name = "" } },
                from_email = fromEmail,
                subject = "Mandrill Integration Test",
                html = "<strong>Example HTML</strong>",
                text = "Example text"
            });

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(toEmail, result.First().Email);
            Assert.AreEqual(EmailResultStatus.Sent, result.First().Status);
        }
Ejemplo n.º 5
0
        public static List <EmailResult> SendMail(List <string> toMails, string subject, string htmlBody, bool async = false)
        {
            try
            {
                var api = new MandrillApi(_mandrillApiKey);

                var email = new EmailMessage()
                {
                    from_email = _senderEmail,
                    subject    = subject,
                    html       = htmlBody
                };
                var to = toMails.Select(mailTo => new EmailAddress(mailTo)).ToList();

                email.to = to;
                if (async)
                {
                    var result = api.SendMessageAsync(email);
                    return(result.Result);
                }
                return(api.SendMessage(email));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        public void SendEmail()
        {
            //create a new message object
            var message = new MandrillApi(Apikey, true);

            //send the mail
            try
            {
                var emailMessage = new EmailMessage()
                {
                    to          = To,
                    subject     = Subject,
                    raw_message = Message,
                    from_email  = From.email,
                    from_name   = From.name
                };

                //message.SendRawMessage(emailMessage);

                message.SendMessage(To, Subject, Message, From, new DateTime());
            }
            catch (System.Exception ex)
            {
                throw;
                // log the error
            }
        }
    public async Task Should_Reschedule_Message()
    {
      if (!IsPaidAccount)
        Assert.Ignore("Not a paid account");
      // Setup
      string apiKey = ConfigurationManager.AppSettings["APIKey"];
      string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
      string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

      // Exercise
      var api = new MandrillApi(apiKey);

      List<EmailResult> result = await api.SendMessage(new SendMessageRequest(new EmailMessage
        {
          To =
            new List<EmailAddress> {new EmailAddress {Email = toEmail, Name = ""}},
          FromEmail = fromEmail,
          Subject = "Mandrill Integration Test",
          Html = "<strong>Example HTML</strong>",
          Text = "Example text"
        }){
        SendAt = DateTime.Now.AddMinutes(5)
      });

      ScheduledEmailResult rescheduleResponse =
        await api.RescheduleMessage(new RescheduleMessageRequest(result.First().Id, DateTime.Now.AddMinutes(10)));

      Assert.AreEqual(result.First().Id, rescheduleResponse.Id);
    }
Ejemplo n.º 8
0
        public void SendAdminProfileEmail(Guid?Token, string Email)
        {
            //email payload
            var ActivateUserEmail = new SendMessageRequest(new EmailMessage
            {
                To =
                    new List <EmailAddress> {
                    new EmailAddress {
                        Email = Email, Name = "Bringpro"
                    }
                },
                FromEmail = ConfigService.MandrillFromEmail,

                Html    = "Activate Account Mandrill Test. Click this link to activate your account " + "http://bringpro.dev/bringpro/authentication/" + Token,
                Subject = "Activate your bringpro account.",
            });
            //sets api key to api key stored in config file - makes easily changeable
            var api = new MandrillApi(ConfigService.MandrillApiKey);

            //Mandrill Requires functions to be set as async.
            //This line of code lets us run void functions asynchronously
            //Purpose - to match interface signatures with sendgrid interface
            //Will be in ALL Mandrill Functions
            Task.Run(async() => await api.SendMessage(ActivateUserEmail));
        }
Ejemplo n.º 9
0
        public ActionResult SendFaleConosco()
        {
            MandrillApi         mandril  = new MandrillApi(NimbusConfig.MandrillToken);
            EmailMessage        mensagem = new EmailMessage();
            List <EmailAddress> address  = new List <EmailAddress>();


            try
            {
                mensagem.from_email = "*****@*****.**";
                mensagem.from_name  = "Fale conosco";
                mensagem.subject    = "[" + Request.Form["slcFaleConosco"] + "]";
                mensagem.text       = "Usuário: " + Request.Form["iptNameFaleConosco"] + " " + Request.Form["iptLastNameFaleConosco"] + " \n" +
                                      "E-mail: " + Request.Form["iptEmailFaleConosco"] + "\n" +
                                      "Tipo: " + Request.Form["slcFaleConosco"] + " \n" +
                                      "Mensagem: " + Request.Form["txtaMsgFaleConosco"] + "\n\n\n\n";

                address.Add(new EmailAddress("***REMOVED***"));
                mensagem.to = address;

                var result = mandril.SendMessage(mensagem);
                if (result[0].Status == EmailResultStatus.Sent)
                {
                    return(Redirect("/userprofile"));
                }
                else
                {
                    return(Redirect("/pageerror404"));    //tem q arrumar
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 10
0
        public async Task SendFeedback(FeedbackParameters feedbackParameters)
        {
            SessionInfo sessionInfo     = idInfoAccessor_.GetSessionInfo();
            var         applicationUser = await accountRepository_.Value.FindUserByAccountIdAsync(sessionInfo.AccountId);



            var emailMessage = new EmailMessage();

            emailMessage.FromName  = applicationUser.UserName;
            emailMessage.FromEmail = "*****@*****.**";
            emailMessage.To        = new[] { new EmailAddress(feedbackEmailAddress_) };
            emailMessage.Text      = $"User Email: {applicationUser.Email}\n\n{JavaScriptEncoder.Default.Encode(HtmlEncoder.Default.Encode(feedbackParameters.Feedback))}";

            var messageRequest = new SendMessageRequest(emailMessage);
            List <EmailResult> emailResults = await mandrillApi_.SendMessage(messageRequest);

            foreach (var item in emailResults)
            {
                if (item.Status == EmailResultStatus.Rejected)
                {
                    throw new ServerErrorException($"Sending email to {item.Email} failed with reason: {item.RejectReason}");
                }

                if (item.Status == EmailResultStatus.Invalid)
                {
                    throw new InvalidArgumentException($"Sending email to {item.Email} is invalid");
                }
            }
        }
Ejemplo n.º 11
0
        //Test
        public void SendEmail(MandrillRequestModelTest model)
        {
            //Setup Test
            model.apiKey    = ConfigService.MandrillApiKey;
            model.toEmail   = ConfigService.MandrillTestEmail;
            model.fromEmail = ConfigService.MandrillFromEmail;

            //sets api key to api key stored in config file - makes easily changeable
            var api = new MandrillApi(model.apiKey);

            //mandrill payload
            var sendMessageRequest = new SendMessageRequest(new EmailMessage
            {
                To =
                    new List <EmailAddress> {
                    new EmailAddress {
                        Email = model.toEmail, Name = "Bringpro"
                    }
                },
                FromEmail = model.fromEmail,
                Subject   = "Mandrill Integration Test",
                Html      = "<strong>Scheduled Email.</strong>",
                Text      = "Example text"
            });

            Task.Run(async() => await api.SendMessage(sendMessageRequest));
        }
Ejemplo n.º 12
0
        public virtual List <IMailResponse> Send(MailAttributes mailAttributes)
        {
            var mail     = GenerateProspectiveMailMessage(mailAttributes);
            var response = new List <IMailResponse>();


            List <EmailResult> resp = null;

            var completeEvent = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((obj) =>
            {
                resp = client.SendMessage(new SendMessageRequest(mail)).Result;
                completeEvent.Set();
            });

            completeEvent.WaitOne();

            response.AddRange(resp.Select(result => new MandrillMailResponse
            {
                Email        = result.Email,
                Status       = MandrillMailResponse.GetProspectiveStatus(result.Status.ToString()),
                RejectReason = result.RejectReason,
                Id           = result.Id
            }));

            return(response);
        }
Ejemplo n.º 13
0
    public async Task Message_With_Send_At_Is_Scheduled_For_Paid_Account()
    {
      if (!IsPaidAccount)
        Assert.Ignore("Not a paid account");

      // Setup
      string apiKey = ConfigurationManager.AppSettings["APIKey"];
      string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
      string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

      // Exercise
      var api = new MandrillApi(apiKey);

      List<EmailResult> result = await api.SendMessage(new SendMessageRequest(new EmailMessage
        {
          To =
            new List<EmailAddress> {new EmailAddress {Email = toEmail, Name = ""}},
          FromEmail = fromEmail,
          Subject = "Mandrill Integration Test",
          Html = "<strong>Scheduled Email</strong>",
          Text = "Example text"
        }){
        SendAt = DateTime.Now.AddMinutes(5)
      });

      // Verify
      Assert.AreEqual(1, result.Count);
      Assert.AreEqual(toEmail, result.First().Email);
      Assert.AreEqual(EmailResultStatus.Scheduled, result.First().Status);

      //Tear down
      await api.CancelScheduledMessage(new CancelScheduledMessageRequest(result.First().Id));
    }
Ejemplo n.º 14
0
        public async Task Should_Reschedule_Message()
        {
            if (!IsPaidAccount)
            {
                Assert.Ignore("Not a paid account");
            }
            // Setup
            string apiKey    = ConfigurationManager.AppSettings["APIKey"];
            string toEmail   = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            List <EmailResult> result = await api.SendMessage(new SendMessageRequest(new EmailMessage
            {
                To =
                    new List <EmailAddress> {
                    new EmailAddress {
                        Email = toEmail, Name = ""
                    }
                },
                FromEmail = fromEmail,
                Subject = "Mandrill Integration Test",
                Html = "<strong>Example HTML</strong>",
                Text = "Example text"
            }){
                SendAt = DateTime.Now.AddMinutes(5)
            });

            ScheduledEmailResult rescheduleResponse =
                await api.RescheduleMessage(new RescheduleMessageRequest(result.First().Id, DateTime.Now.AddMinutes(10)));

            Assert.AreEqual(result.First().Id, rescheduleResponse.Id);
        }
Ejemplo n.º 15
0
        public void Raw_Message_Is_Sent()
        {
            // Setup
            var apiKey = ConfigurationManager.AppSettings["APIKey"];
            string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var message = "From: " + fromEmail + "\n" +
                "Subject: Mandrill Integration Test Raw\n" +
                "To: " + toEmail + "\n" +
                "MIME-Version: 1.0\n" +
                "Content-Type: text/html; charset=utf-8\n" +
                "Content-Transfer-Encoding: 7bit\n" +
                "\n" +
                "Test\n";
            var result = api.SendMessage(new EmailMessage
                                             {
                                                 to =
                                                     new List<EmailAddress> { new EmailAddress { email = toEmail, name = "" } },
                                                 from_email = fromEmail,
                                                 from_name = "",
                                                 raw_message = message
                                             });
            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(toEmail, result.First().Email);
            Assert.AreEqual(EmailResultStatus.Sent, result.First().Status);
        }
        private void CreateAndSendEmailMessageFromTemplate(WebHookEvent evt)
        {
            var metadata = ParseMetadataFromMandrill(evt);
            var message  = new Mandrill.EmailMessage();

            message.to = new List <Mandrill.EmailAddress>()
            {
                new EmailAddress {
                    email = "*****@*****.**"
                },
                new EmailAddress {
                    email = "*****@*****.**"
                }
            };

            message.subject    = String.Format("Bounced email notification", evt.Event);
            message.from_email = "*****@*****.**";


            if (metadata.ContainsKey("CustID"))
            {
                message.AddGlobalVariable("customerID", metadata["CustID"].ToUpper());
            }
            else
            {
                message.AddGlobalVariable("customerID", "Unknown");
            }
            message.AddGlobalVariable("bouncedEmailAddress", evt.Msg.Email);
            message.AddGlobalVariable("application", GetSendingApplicationName(evt));
            message.AddGlobalVariable("timesent", TimeZoneInfo.ConvertTimeFromUtc(evt.Msg.TimeStamp, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).ToString());

            _mandrillApi.SendMessage(message, "mandrill-email-bounce", null);
        }
Ejemplo n.º 17
0
        public void Message_With_Send_At_Is_Scheduled()
        {
            // Setup
            var    apiKey    = ConfigurationManager.AppSettings["APIKey"];
            string toEmail   = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var result = api.SendMessage(new EmailMessage
            {
                to =
                    new List <EmailAddress> {
                    new EmailAddress {
                        email = toEmail, name = ""
                    }
                },
                from_email = fromEmail,
                subject    = "Mandrill Integration Test",
                html       = "<strong>Scheduled Email</strong>",
                text       = "Example text"
            }, DateTime.UtcNow.AddMinutes(5.0));

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(toEmail, result.First().Email);
            Assert.AreEqual(EmailResultStatus.Scheduled, result.First().Status);

            //Tear down
            api.CancelScheduledMessage(result.First().Id);
        }
Ejemplo n.º 18
0
        public static List <Look> SendEmailToFeaturedLookCreator(List <long> lookIds, string tagName)
        {
            var         api   = new MandrillApi(apiKey);
            List <Look> looks = new List <Look>();

            //Send look owenrs congrats email
            if (lookIds.Count > 0)
            {
                //get look details and fill it in
                for (int l = 1; l <= lookIds.Count; l++)
                {
                    Look look = Look.GetLookById(lookIds[l - 1], 0, db);
                    looks.Add(look);
                    var recipients = new List <EmailAddress>();
                    recipients.Add(new EmailAddress(look.creator.emailId, look.creator.userName));
                    var message = new EmailMessage()
                    {
                        to         = recipients,
                        from_email = "*****@*****.**",
                        from_name  = "Cult Collection",
                        subject    = "Your Look Was Featured",
                    };

                    if (look.id > 0)
                    {
                        message.AddGlobalVariable("L1URL", "http://startcult.com/look.html?lookId=" + look.id + "&userName=CultCollection&url=http://startcult.com/images/100x100_identity_.png&utm_source=email&utm_medium=WeeklyDigest&utm_term=consumption");
                        message.AddGlobalVariable("L1IMG", "http://startcult.com/images/looks/" + look.id + ".jpg");
                        message.AddGlobalVariable("U1", look.creator.userName);
                        message.AddGlobalVariable("S1", (look.upVote + look.restyleCount).ToString());
                        message.AddGlobalVariable("L1DESC", look.title);
                    }
                    message.important = true;
                    var result = api.SendMessage(message, "Your Look was Featured", null);

                    //Make it featured
                    if (!string.IsNullOrEmpty(tagName))
                    {
                        string        query        = "EXEC [stp_SS_UpdateLookTagMap] @tName=N'" + tagName + "', @lId=" + lookIds[l - 1] + ", @type=1,@featured=1";
                        SqlConnection myConnection = new SqlConnection(db);

                        try
                        {
                            myConnection.Open();
                            using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection))
                            {
                                SqlCommand cmd = adp.SelectCommand;
                                cmd.CommandTimeout = 300000;
                                cmd.ExecuteNonQuery();
                            }
                        }
                        finally
                        {
                            myConnection.Close();
                        }
                    }
                }
            }
            return(looks);
        }
Ejemplo n.º 19
0
        public virtual List <IMailResponse> Send(MailAttributes mailAttributes)
        {
            var mail     = GenerateProspectiveMailMessage(mailAttributes);
            var response = new List <IMailResponse>();
            var request  = new SendMessageRequest(mail);

            var resp = AsyncHelpers.RunSync(() => _client.SendMessage(request));

            response.AddRange(resp.Select(result => new MandrillMailResponse
            {
                Email        = result.Email,
                Status       = MandrillMailResponse.GetProspectiveStatus(result.Status.ToString()),
                RejectReason = result.RejectReason,
                Id           = result.Id
            }));

            return(response);
        }
Ejemplo n.º 20
0
        public bool sendTokenResetPassword(string userEmail = null)
        {
            MandrillApi  apiMandrill = new MandrillApi(NimbusConfig.MandrillToken);
            EmailMessage mensagem    = new EmailMessage();

            mensagem.from_email = "*****@*****.**";
            mensagem.from_name  = "Portal Nimbus";
            mensagem.subject    = "Redefinição de senha";
            if (userEmail == null)
            {
                userEmail = NimbusUser.Email;
            }
            List <EmailAddress> address = new List <EmailAddress> ();

            address.Add(new EmailAddress(userEmail));
            mensagem.to = address;

            NSCInfo infoToken = new NSCInfo
            {
                TokenGenerationDate = DateTime.Now,
                TokenExpirationDate = DateTime.Now.AddDays(1),
                UserId = -1 * NimbusUser.UserId
            };

            Guid   token;
            string tokeString = Token.GenerateToken(infoToken, out token);

            mensagem.html = " <body style=\"width:80p0x; background-color:#ffffff;\">" +
                            "<div>" +
                            "<img src=\"https://***REMOVED***/imgnimbus/topBar.png\" style=\"width:800px;\" />" +
                            "</div>" +
                            "<div style=\"margin:30px 10% 40px; height:250px;\">" +
                            "Olá " + NimbusUser.FirstName + " " + NimbusUser.LastName + ", <br/>" +
                            "para redefinir sua senha, acesse: " +
                            "<a href=\"http://www.portalnimbus.com.br/resetpassword?reset=" + Uri.EscapeDataString(tokeString) + "\">Redefinir senha</a><br/>" +
                            "*Esse link é válido no período de 1 (um) dia. <br/><br/>" +

                            "</div>" +
                            "<div>" +
                            "<img src=\"https://***REMOVED***/imgnimbus/bottomBar.png\" style=\"width:800px;\" />" +
                            "</div>" +
                            "</body>";


            var result = apiMandrill.SendMessage(mensagem);

            if (result[0].Status == EmailResultStatus.Sent)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 21
0
        public void Send(EmailMessage emailMessage)
        {
            var mandrillResult = mandrillApi.SendMessage(emailMessage);
            var emailResults   =
                mandrillResult.Where(
                    mr => mr.Status == EmailResultStatus.Rejected || mr.Status == EmailResultStatus.Invalid).ToList();

            if (emailResults.Any())
            {
                throw new Exception("Mandrill Send Email Failed: " + emailResults.First().RejectReason);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Send an email
        /// </summary>
        /// <param name="request">Contains detailed email info and optionally provider info (such as ApiKeys)</param>
        /// <param name="messageId">The message id returned by the service provider</param>
        /// <param name="detailMessage">The message returned by the service provider, e.g. "failed to send message", "Sent", "Message Queued for delivery"</param>
        /// <returns>True if email was sent successfully</returns>
        public override bool SendMail(SendMailRequest request, out string messageId, out string detailMessage)
        {
            // Create request
            string      apiKey = GetApiKey(request);
            MandrillApi api    = new MandrillApi(apiKey);

            // Email details
            EmailMessage msg = new EmailMessage();

            msg.FromEmail = request.From;
            msg.To        = request.To.Select(e => new EmailAddress(e));
            msg.Text      = request.Text;

            // Send email
            SendMessageRequest         smReq = new SendMessageRequest(msg);
            Task <List <EmailResult> > task  = api.SendMessage(smReq);

            task.Wait();

            // process response
            messageId     = "";
            detailMessage = "";

            EmailResult er = null;

            if (task.Result != null && task.Result.Count > 0)
            {
                er = task.Result[0];
            }

            if (er == null)
            {
                detailMessage = "Invalid return result from provider.";
                return(false);
            }

            messageId     = er.Id;
            detailMessage = er.Status.ToString();

            if (er.Status == EmailResultStatus.Queued ||
                er.Status == EmailResultStatus.Scheduled ||
                er.Status == EmailResultStatus.Sent)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        public List <EmailDeliveryResult> Send()
        {
            _message.Attachments = _attachments;

            var results = Task.Run(() => _api.SendMessage(new SendMessageRequest(_message))).Result;

            return(results.Select(e => new EmailDeliveryResult()
            {
                Email = e.Email,
                Success = e.Status == EmailResultStatus.Sent || e.Status == EmailResultStatus.Queued || e.Status == EmailResultStatus.Scheduled,
                ProviderResult = e.RejectReason,
                ProviderId = e.Id
            }).ToList());
        }
Ejemplo n.º 24
0
        public Task SendMail(MailModel mm)
        {
            var msg    = new EmailMessage();
            var recips = new List <EmailAddress> {
                new EmailAddress(mm.To)
            };

            msg.Html      = mm.Message;
            msg.Subject   = mm.Subject;
            msg.To        = recips;
            msg.FromName  = EmailFromName;
            msg.FromEmail = EmailFromAddress;

            return(_mandrill.SendMessage(new SendMessageRequest(msg)));
        }
        public Task SendEmailAsync(string email, string subject, string message)
        {
            var lst = new List <Mandrill.Models.EmailAddress>();

            lst.Add(new Mandrill.Models.EmailAddress(email));

            var task = _mandrill.SendMessage(new SendMessageRequest(new EmailMessage
            {
                FromEmail = EmailFromAddress,
                FromName  = EmailFromName,
                Subject   = subject,
                To        = lst,
                Html      = message
            }));

            return(task);
        }
Ejemplo n.º 26
0
        public bool SendFeedback(int type, string message)
        {
            MandrillApi         mandril  = new MandrillApi(NimbusConfig.MandrillToken);
            EmailMessage        mensagem = new EmailMessage();
            List <EmailAddress> address  = new List <EmailAddress>();


            try
            {
                if (type == 1)
                {
                    mensagem.subject = "[feedbackPositivo]";
                }
                else if (type == 0)
                {
                    mensagem.subject = "[feedbackNegativo]";
                }

                string nameUser = NimbusUser.FirstName != null? NimbusUser.FirstName : "nulo";
                nameUser            = nameUser + " " + NimbusUser.LastName != null? NimbusUser.LastName : "nulo";
                mensagem.from_email = "*****@*****.**";
                mensagem.from_name  = "Feedback";
                mensagem.text       = "Tipo: " + mensagem.subject.Replace("feedback", "") + " \n" +
                                      "Usuário: " + nameUser + "\n" +
                                      "Mensagem: " + message + "\n\n\n\n";

                address.Add(new EmailAddress("***REMOVED***"));
                mensagem.to = address;

                var result = mandril.SendMessage(mensagem);
                if (result[0].Status == EmailResultStatus.Sent)
                {
                    return(true);
                }
                else
                {
                    return(false); //tem q arrumar
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 27
0
        public String EmailAccountActivation(String email, String url, String name)
        {
            string result = "error";

            try
            {
                UserInfo user = new UserInfo();
                Mandrill.Models.TemplateInfo template = apimd.TemplateInfo("Correo_verificacion");
                Mandrill.EmailMessage        msg      = new Mandrill.EmailMessage
                {
                    from_email = "*****@*****.**"
                    ,
                    from_name = "YoVendoRecarga.com"
                    ,
                    auto_text = false
                    ,
                    subject = "Activar Cuenta"
                    ,
                    to = new List <Mandrill.EmailAddress> {
                        new Mandrill.EmailAddress(email, name, "to")
                    }
                    ,
                    bcc_address = "*****@*****.**"
                    ,
                    merge_language = "mailchimp"
                    ,
                    merge = true
                };
                msg.AddGlobalVariable("NAME", name);
                msg.AddGlobalVariable("LINK", url);

                apimd.SendMessage(msg, template.name, null);
            }
            catch (Exception)
            {
                result = "error";
                throw;
            }

            return(result);
        }
Ejemplo n.º 28
0
        public void Template_Message_Is_Sent()
        {
            // Setup
            var apiKey = ConfigurationManager.AppSettings["APIKey"];
            string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var result = api.SendMessage(new EmailMessage
                                             {
                                                 to =
                                                     new List<EmailAddress>
                                                         {new EmailAddress {email = toEmail, name = ""}},
                                                 from_email = fromEmail,
                                                 subject = "Mandrill Integration Test",
                                             }, "Test", new List<TemplateContent>{new TemplateContent{name="model1",content = "Content1"}, new TemplateContent{name = "model2", content = "Content2"}});

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(toEmail, result.First().Email);
            Assert.AreEqual(EmailResultStatus.Sent, result.First().Status);
        }
    public async Task Should_Schedule_Then_List_Scheduled_And_Cancel_Message()
    {
      if (!IsPaidAccount)
        Assert.Ignore("Not a paid account");
      // Setup
      string apiKey = ConfigurationManager.AppSettings["APIKey"];
      string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
      string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

      // Exercise
      var api = new MandrillApi(apiKey);

      List<EmailResult> result = await api.SendMessage(new SendMessageRequest(new EmailMessage
        {
          To =
            new List<EmailAddress> {new EmailAddress {Email = toEmail, Name = ""}},
          FromEmail = fromEmail,
          Subject = "Mandrill Integration Test",
          Html = "<strong>Example HTML</strong>",
          Text = "Example text"
        }){
        SendAt = DateTime.Now.AddMinutes(5)
      });

      List<ScheduledEmailResult> scheduled =
        await api.ListScheduledMessages(new ListScheduledMessagesRequest {ToEmail = toEmail});

      //Verify that message was scheduled
      Assert.AreEqual(1, scheduled.Count(s => s.Id == result.First().Id));

      await api.CancelScheduledMessage(new CancelScheduledMessageRequest(result.First().Id));
      scheduled = await api.ListScheduledMessages(new ListScheduledMessagesRequest {ToEmail = toEmail});

      //Verify that message was canceled.
      Assert.AreEqual(0, scheduled.Count(s => s.Id == result.First().Id));
    }
Ejemplo n.º 30
0
        public void Scheduled_Message_Is_Canceled()
        {
            // Setup
            var apiKey = ConfigurationManager.AppSettings["APIKey"];
            string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var messages = api.SendMessage(new EmailMessage
            {
                to =
                    new List<EmailAddress> { new EmailAddress { email = toEmail, name = "" } },
                from_email = fromEmail,
                subject = "Mandrill Integration Test",
                html = "<strong>Scheduled Email</strong>",
                text = "Example text"
            }, DateTime.UtcNow.AddMinutes(5.0));

            var scheduled = api.ListScheduledMessages(toEmail);

            //Verify that message was scheduled
            Assert.AreEqual(1, scheduled.Count(s => s.Id == messages.First().Id));

            api.CancelScheduledMessage(messages.First().Id);
            scheduled = api.ListScheduledMessages(toEmail);

            //Verify that message was cancelled.
            Assert.AreEqual(0, scheduled.Count(s => s.Id == messages.First().Id));
        }
Ejemplo n.º 31
0
        public void Scheduled_Message_Is_Rescheduled()
        {
            // Setup
            var apiKey = ConfigurationManager.AppSettings["APIKey"];
            string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var messages = api.SendMessage(new EmailMessage
                {
                    to =
                        new List<EmailAddress> { new EmailAddress { email = toEmail, name = "" } },
                    from_email = fromEmail,
                    subject = "Mandrill Integration Test",
                    html = "<strong>Scheduled Email</strong>",
                    text = "Example text"
                }, DateTime.UtcNow.AddMinutes(5.0));

            var message = api.ListScheduledMessages().Find(s => s.Id == messages.First().Id);

            var rescheduled = api.RescheduleMessage(message.Id, message.SendAt.AddMinutes(5.0));

            //Verify
            Assert.Greater(rescheduled.SendAt, message.SendAt);

            //Tear down
            api.CancelScheduledMessage(rescheduled.Id);
        }
Ejemplo n.º 32
0
        public void Message_With_Send_At_Is_Scheduled()
        {
            // Setup
            var apiKey = ConfigurationManager.AppSettings["APIKey"];
            string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
            string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

            // Exercise
            var api = new MandrillApi(apiKey);

            var result = api.SendMessage(new EmailMessage
            {
                to =
                    new List<EmailAddress> { new EmailAddress { email = toEmail, name = "" } },
                from_email = fromEmail,
                subject = "Mandrill Integration Test",
                html = "<strong>Scheduled Email</strong>",
                text = "Example text"
            }, DateTime.UtcNow.AddMinutes(5.0));

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(toEmail, result.First().Email);
            Assert.AreEqual(EmailResultStatus.Scheduled, result.First().Status);

            //Tear down
            api.CancelScheduledMessage(result.First().Id);
        }
Ejemplo n.º 33
0
    public async Task Should_Send_Email_Message_With_Attachments()
    {
        // Setup
        string apiKey = ConfigurationManager.AppSettings["APIKey"];
        string toEmail = ConfigurationManager.AppSettings["ValidToEmail"];
        string fromEmail = ConfigurationManager.AppSettings["FromEMail"];

        // Exercise
        var api = new MandrillApi(apiKey);

        var attachment = new EmailAttachment()
                             {
                                 Content = Convert.ToBase64String(File.ReadAllBytes(@".\Data\test_attachment.txt")),
                                 Base64 = true,
                                 Name = "Test söme.txt",
                                 Type = "text/plain"
                             };

        try
        {
            List<EmailResult> result =
                await
                api.SendMessage(
                    new SendMessageRequest(
                    new EmailMessage
                        {
                            To = new List<EmailAddress> { new EmailAddress { Email = toEmail, Name = "" } },
                            FromEmail = fromEmail,
                            Subject = "Mandrill Integration Test",
                            Html = "<strong>Example HTML</strong>",
                            Text = "Example text",
                            Attachments = new List<EmailAttachment>() { attachment }
                        }));

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(toEmail, result.First().Email);
            Assert.AreEqual(EmailResultStatus.Queued, result.First().Status);
        }
        catch (MandrillException ex)
        {
            Console.WriteLine("Error: {0}", ex.Error.Message);
            throw;
        }
    }