private static bool DoesEmailExistInInbox(EmailMsg msg) { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2016); service.Credentials = new WebCredentials(emailAccount, accountPassword); service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx"); SearchFilter searchFilter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeSent, msg.DateTimeSent); ItemView view = new ItemView(10); var emails = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view); bool found = true; foreach (var item in emails) { if (item.Subject.Equals(msg.Subject)) { found = true; item.Delete(DeleteMode.MoveToDeletedItems); break; } } return(found); }
public JsonResult OnPost([FromBody] EmailMsg emailMsg) { string emailTo = dataAccess.GetEmail(); MailMessage mail = new MailMessage(); mail.To.Add(emailTo); mail.Subject = emailMsg.Name + " - " + emailMsg.Subject; mail.Body = emailMsg.Message + "\n" + emailMsg.Name; mail.IsBodyHtml = false; mail.Sender = new MailAddress("*****@*****.**"); if (emailMsg.IsValidEmail(emailMsg.Email) != false) { mail.From = new MailAddress(emailMsg.Email); SmtpClient smtpClient = new SmtpClient("w019cc1a.kasserver.com"); smtpClient.Port = 587; smtpClient.UseDefaultCredentials = true; smtpClient.EnableSsl = true; smtpClient.Credentials = new System.Net.NetworkCredential("m051a2c2", "DzFEHDd4pAzdK2yX"); smtpClient.Send(mail); return(new JsonResult(emailMsg)); } else { emailMsg.Email = "false"; return(new JsonResult(emailMsg)); } }
public static bool SendEmail(ref EmailMsg msg) { bool uspeh = false; StringBuilder sb = new StringBuilder(); sb.AppendLine("-----------------------------------"); sb.AppendLine("This message is recived via Web, FROM visitor - (" + msg.Email + ")"); sb.AppendLine("----------------------------------"); sb.AppendLine(""); sb.AppendLine(msg.Message); try { NetworkCredential uplogin = new NetworkCredential("*****@*****.**", "A1teslasolar."); SmtpClient smtp = new SmtpClient("mail.teslasolarsolutions.com"); smtp.Credentials = uplogin; MailMessage eMessage = new MailMessage(); eMessage.From = new MailAddress("*****@*****.**"); eMessage.Bcc.Add(new MailAddress("[email protected] ")); eMessage.To.Add(new MailAddress("*****@*****.**")); eMessage.CC.Add(new MailAddress(msg.Email)); eMessage.Subject = "TeslaWeb.Visitor - " + msg.Subject; eMessage.Body = sb.ToString(); smtp.Send(eMessage); uspeh = true; } catch (Exception ex) { msg.ErrorMsg = ex.Message + " : " + ex.StackTrace; } return(uspeh); }
public bool Save(EmailMsg emailMsg) { var data = Load <DataInfo>() ?? new DataInfo(); data.Add(emailMsg); return(Save <DataInfo>(data)); }
public async Task ProcessQueueMessage([QueueTrigger("emails")] EmailMsg message) { var client = new RestClient { BaseUrl = new Uri(_mailgunOptions.ApiBaseUrl), Authenticator = new HttpBasicAuthenticator("api", _mailgunOptions.ApiKey) }; var request = new RestRequest { Resource = "messages", Method = Method.POST }; request.AddParameter("from", message.SenderEmailAddress); request.AddParameter("to", message.RecipientEmailAddressesCommaSeperated); request.AddParameter("subject", message.Header); request.AddParameter("text", message.Body); var response = await client.ExecuteTaskAsync(request); // how to handle all exceptions? if (response.ErrorException != null) { throw response.ErrorException; } }
public LoadingScreen(EmailMsg emailMsg) { InitializeComponent(); LoadingLabel.Content = "Sending ticket..."; var answer = Email.SendEmailForm(emailMsg); LoadingLabel.Content = $"Result: {answer.Result.StatusCode}"; }
public void Add(EmailMsg emailMsg) { if (EmailMsg == null) { EmailMsg = new List <EmailMsg>(); } EmailMsg.Add(emailMsg); }
public static void SendEmail(Trade trade, EmailMsg Msg, bool AdminEmail) { _Msg = Msg; _EmailTrade = trade; _Admin = AdminEmail; BW = new BackgroundWorker(); BW.DoWork += new DoWorkEventHandler(BW_DoWork); BW.RunWorkerAsync(); }
private void SendTicket(object sender, MouseButtonEventArgs e) { if (HeaderField.Text == "" || HeaderField.Text == _startingHead || BodyField.Text == "" || BodyField.Text == _startingBody) { NotificationWidget(); } else { var emailMsg = new EmailMsg(HeaderField.Text, BodyField.Text); MainWindow.DataInfo.Add(emailMsg); Switcher.Switch(new LoadingScreen(emailMsg)); } }
public ActionResult NLog(SendEmail sm) { string key = ConfigurationManager.AppSettings["Sendgrid.Key"]; SendGridEmailService messageSvc = new SendGridEmailService(key); string htmlBody = $@"<ul> <li>Name: {sm.Name}</li> <li>Email: {sm.Email}</li> <li>Message Details: {sm.Message}</li> </ul>"; var msg = new EmailMsg() { Body = htmlBody, Subject = sm.Subject, From = sm.Name, Recipient = sm.Email }; var fileName = FileConverter.GetFilePath("logs\\2018-05-21.log"); var fileData = FileConverter.Convert(fileName); messageSvc.SendMail(msg, true, fileName, fileData); return(RedirectToAction("Success", "Home")); //attaches file //string envPath = HttpRuntime.AppDomainAppPath; //string fileName = $"{envPath}\\Content\\assets\\images\\logo_dark.png"; //byte[] imageData = null; //FileInfo fileInfo = new FileInfo(fileName); //long imageFileLength = fileInfo.Length; //FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); //BinaryReader br = new BinaryReader(fs); //imageData = br.ReadBytes((int)imageFileLength); //messageSvc.SendMail(msg, true, fileName, imageData); }
public ActionResult Contact(EmailMsg msg) { ViewBag.Message = "Your email page."; if (ModelState.IsValid) { msg.IsSent = EmailService.SendEmail(ref msg); if (msg.IsSent) { msg = new EmailMsg(); msg.Poraka = "The message is sent. Thank you."; msg.IsSent = true; return(RedirectToRoute("Contact", new { EmailSent = 1 })); } else { msg.Poraka = " Ooops, we have a problem.Message NOT sent. Try again."; } } return(View(msg)); }
private async Task <bool> SendEmail(EmailMsg message) { try { var result = await Email.SendEmailForm(message); if (result.StatusCode == HttpStatusCode.Accepted) { //LoadingLabel.Content = "Sent successfully"; return(true); } return(false); } catch (Exception ex) { MessageBox.Show("Message failed to send\nEnsure you are connected to the internet", "Message send error", MessageBoxButton.OK, MessageBoxImage.Error); var _ = new Error(ex); return(false); } }
public string PushEmailMessage(EmailMsg msg) { try { bool suc = PushServer.Instance().PushEmail(msg.Address, msg.Content); if (suc) { #region 添加到已发送成功列表 using (var db = new MPModel()) { MsgSent model = new MsgSent() { Title = msg.Title, Content = msg.Content, RequestTime = msg.RequestTime, ExpriedTime = msg.ExpriedTime, MType = (int)MsgType.Html, RegName = "", Phone = "", Address = msg.Address, SendTime = DateTime.Now }; db.MsgSents.Add(model); int rows = db.SaveChanges(); return(rows > 0 ? "SUCCESS" : "ERROR"); } #endregion } else { #region 添加到待发送成功列表 using (var db = new MPModel()) { MsgToBeSent model = new MsgToBeSent() { Title = msg.Title, Content = msg.Content, RequestTime = msg.RequestTime, ExpriedTime = msg.ExpriedTime, MType = (int)MsgType.Sms, RegName = "", Phone = "", Address = msg.Address }; db.MsgToBeSents.Add(model); int rows = db.SaveChanges(); return(rows > 0 ? "SUCCESS" : "ERROR"); } #endregion } } catch (Exception) { throw; } }