Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Net;
- using System.Net.Mail;
- using System.Threading.Tasks;
- using System.Web;
- namespace thePure5.Models
- {
- public class OrderServices
- {
- public async static Task OrderNowAsync(string email, string subject, string message)
- {
- try
- {
- var _email = "magdalena.kkirova@gmail.com";
- var _epass = ConfigurationManager.AppSettings["EmailPassword"];
- var _dispName = "Order Form";
- MailMessage myMessage = new MailMessage();
- myMessage.To.Add("magdalena.kkirova@gmail.com");
- myMessage.From = new MailAddress(_email, _dispName);
- myMessage.Subject = subject;
- myMessage.Body = message;
- myMessage.IsBodyHtml = true;
- using (SmtpClient smtp = new SmtpClient())
- {
- smtp.EnableSsl = true;
- smtp.Host = "smtp.gmail.com"; //if using hotmail to send emails
- smtp.Port = 587;
- smtp.UseDefaultCredentials = false;
- smtp.Credentials = new NetworkCredential(_email, _epass);
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
- await smtp.SendMailAsync(myMessage);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public async static Task SendBulkEmailAsync(string[] emails, string subject, string message, List<HttpPostedFileBase> attachments)
- {
- try
- {
- var _email = "magdalena.kkirova@gmail.com";
- var _epass = ConfigurationManager.AppSettings["EmailPassword"];
- var _dispName = "DisplayName";
- MailMessage myMessage = new MailMessage();
- myMessage.From = new MailAddress(_email, _dispName);
- myMessage.Subject = subject;
- myMessage.Body = message;
- myMessage.IsBodyHtml = true;
- using (SmtpClient smtp = new SmtpClient())
- {
- smtp.EnableSsl = true;
- smtp.Host = "smtp.gmail.com"; //if using hotmail to send emails
- smtp.Port = 465;
- smtp.UseDefaultCredentials = false;
- smtp.Credentials = new NetworkCredential(_email, _epass);
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
- await smtp.SendMailAsync(myMessage);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement