public string SendEmail(SendEmail emailMessage)
        {
            using (var session = DocumentStore.GetStore().OpenSession(DocumentStore.ConfigurationDatabaseName()))
            {
                var mandrillConfig = session.Load<MailgunConfiguration>("MandrillConfig");
                if (mandrillConfig == null)
                {
                    throw new NotImplementedException();
                }

                var api = new MandrillApi(mandrillConfig.ApiKey);
                var message = new MailChimp.Types.Mandrill.Messages.Message();

                message.Html = emailMessage.BaseRequest.BodyHtml;
                message.Text = emailMessage.BaseRequest.BodyText;
                message.To = new[]{new MailChimp.Types.Mandrill.Messages.Recipient(emailMessage.BaseRequest.ToAddress, emailMessage.BaseRequest.ToAddress), }; //new List<EmailAddress>() {new EmailAddress(emailMessage.BaseRequest.ToAddress)};
                message.Subject = emailMessage.BaseRequest.Subject;
                message.FromEmail = emailMessage.BaseRequest.FromAddress;
                message.FromName = emailMessage.BaseRequest.FromDisplayName;
                var result = api.Send(message);
                if (result == null || result.Count == 0)
                    throw new Exception("Email should be getting something back....");
                if (result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Invalid || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Bounced || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Rejected || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.SoftBounced)
                    throw new Exception("Some exception because email failed");
                return result[0].ID;
            }
        }
示例#2
0
        public ActionResult Send()
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de");

            var api        = new MandrillApi("VVWfyUXm5J4ZJVZ8ziOVzA");
            var recipients = new List <Mandrill.Messages.Recipient>();

            recipients.Add(new Mandrill.Messages.Recipient("*****@*****.**", "PAUL Kontakt Formular"));

            string body = "";

            foreach (string key in Request.Form)
            {
                var value = Request.Form[key];
                body += key + System.Environment.NewLine;
                body += value + System.Environment.NewLine + System.Environment.NewLine;
            }

            var msg = new Mandrill.Messages.Message()
            {
                To        = recipients.ToArray(),
                FromEmail = "*****@*****.**",
                Subject   = "PAUL WebFormular",
                Text      = body
            };

            api.Send(msg);

            return(Json(new { success = true }));
        }
        public string SendEmail(SendEmail emailMessage)
        {
            using (var session = DocumentStore.GetStore().OpenSession(DocumentStore.ConfigurationDatabaseName()))
            {
                var mandrillConfig = session.Load <MailgunConfiguration>("MandrillConfig");
                if (mandrillConfig == null)
                {
                    throw new NotImplementedException();
                }

                var api     = new MandrillApi(mandrillConfig.ApiKey);
                var message = new MailChimp.Types.Mandrill.Messages.Message();

                message.Html      = emailMessage.BaseRequest.BodyHtml;
                message.Text      = emailMessage.BaseRequest.BodyText;
                message.To        = new[] { new MailChimp.Types.Mandrill.Messages.Recipient(emailMessage.BaseRequest.ToAddress, emailMessage.BaseRequest.ToAddress), }; //new List<EmailAddress>() {new EmailAddress(emailMessage.BaseRequest.ToAddress)};
                message.Subject   = emailMessage.BaseRequest.Subject;
                message.FromEmail = emailMessage.BaseRequest.FromAddress;
                message.FromName  = emailMessage.BaseRequest.FromDisplayName;
                var result = api.Send(message);
                if (result == null || result.Count == 0)
                {
                    throw new Exception("Email should be getting something back....");
                }
                if (result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Invalid || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Bounced || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Rejected || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.SoftBounced)
                {
                    throw new Exception("Some exception because email failed");
                }
                return(result[0].ID);
            }
        }
示例#4
0
        public ActionResult Send_Email(string Toemail, FormCollection form)
        {
            try
            {
                OLX_Context cont = new OLX_Context();
                Message     m    = new Message();
                m.MessageBody = form["Message_Body"];
                m.From        = form["Sender_Email"];
                m.To          = Toemail;
                cont.Messages.Add(m);
                cont.SaveChanges();

                var api     = new MandrillApi("UfOYDeGFVADrZwuEoVdg3g");
                var message = new Mandrill.Messages.Message();
                message.Subject   = "Dummy OLX Message";
                message.Text      = form["Message_Body"];
                message.Text     += "\nFROM: ";
                message.Text     += form["Sender_Email"];
                message.FromEmail = "*****@*****.**";
                message.FromName  = "HaZa_OLX";
                message.To        = new[] { new Mandrill.Messages.Recipient(Toemail, "test") };

                api.Send(message);
                Response.Write("Email Sent");
            }
            catch (Exception ex)
            {
                Response.Write("Could not send the e-mail - error: " + ex.Message);
            }

            return(null);
        }
示例#5
0
		public bool SendEmail(string name, string to, string data, EmailType emailType)
		{
			try
			{
				string Subject = "";
				string HtmlBody = "";
				string TextBody = "";
				switch (emailType)
				{
					case EmailType.subscription:
						Subject = "Welcome to IBO Virtual";
						HtmlBody = GetSubscriptionHtml(name);
						TextBody = GetSubscriptionText(name);
						break;
					case EmailType.resetEmail:
						Subject = "IBO Virtual Reset Password";
						HtmlBody = GetResetMailHtml(name, data);
						TextBody = GetResetMailText(name, data);
						break;
					default:
						break;
				}

				List<Mandrill.Messages.Recipient> recipients = new List<Mandrill.Messages.Recipient>();
				Mandrill.Messages.Recipient recipient = new Mandrill.Messages.Recipient(to, name);
				recipients.Add(recipient);

				MandrillApi server = new MandrillApi(serverToken);
				Mandrill.Messages.Message message = new Mandrill.Messages.Message();

				message.FromEmail = fromEmail;
				message.FromName = fromName;
				message.Subject = Subject;
				message.Html = HtmlBody;
				message.Text = TextBody;
				message.To = recipients.ToArray();
				message.TrackOpens = true;

				MVList<Mandrill.Messages.SendResult> results = server.Send(message);

				if (results.Count > 0)
				{
					Mandrill.Messages.SendResult result = results[0];
					if (result.Status == Mandrill.Messages.Status.Sent)
					{
						return true;
					}
					else
					{
						return false;
					}
				}

			}
			catch
			{ }
			return false;
		}
示例#6
0
        public static void sendAccountActivationEmail()
        {
            MandrillApi api = new MandrillApi("3o-nF0RHNIA7k1poegC-_g");

            Mandrill.Messages.Message     message       = new Mandrill.Messages.Message();
            Mandrill.Messages.Recipient[] listAddresses = new Mandrill.Messages.Recipient[1];

            listAddresses[0] = new Mandrill.Messages.Recipient("*****@*****.**", "Fulanito");

            message.FromEmail   = "*****@*****.**";
            message.FromName    = "Contact Manager";
            message.Html        = "<h1>Testing</h1><p>Probando</p>";
            message.Subject     = "Testing";
            message.TrackClicks = true;
            message.Important   = true;
            message.To          = listAddresses;

            MVList <Mandrill.Messages.SendResult> result = api.Send(message);
            string oeoe = "";
        }
        public void SendEmail(MailMessage mailMessage, string[] tags = null)
        {
            try
            {
                var message = new MailChimp.Types.Mandrill.Messages.Message
                {
                    To        = mailMessage.To.Select(o => new MailChimp.Types.Mandrill.Messages.Recipient(o.Address, o.DisplayName)).ToArray(),
                    FromEmail = mailMessage.From.Address,
                    FromName  = String.IsNullOrEmpty(mailMessage.From.DisplayName) ? mailMessage.From.DisplayName : "DefaultName",
                    Subject   = mailMessage.Subject,
                    Html      = mailMessage.IsBodyHtml ? mailMessage.Body : null,
                    Text      = mailMessage.IsBodyHtml ? null : mailMessage.Body,
                };

                if (mailMessage.ReplyToList.Any())
                {
                    message.Headers = new MCDict <MailChimp.Types.Mandrill.Messages.Header> {
                        { "Reply-To", mailMessage.ReplyToList.First().Address }
                    }
                }
                ;

                if (mailMessage.Bcc.Any())
                {
                    message.BccAddress = mailMessage.Bcc.First().Address;
                }
                if (tags != null)
                {
                    message.Tags = tags;
                }

                MVList <MailChimp.Types.Mandrill.Messages.SendResult> result = _mandrillApi.Send(message);
            }
            catch (Exception)
            {
                //TODO: Log
            }
        }