public int SendToUsersSubscribed(Message topicMessage, List<User> users, string body, string url, string unsubscribeUrl, bool handleExceptions) { int sentMailsCount = 0; foreach (User u in users) { if ((u.EmailPolicy & EmailPolicy.SendFromSubscriptions) > 0) { try { SendEmailToSubscriptor(topicMessage, u, body, url, unsubscribeUrl); sentMailsCount++; } catch (Exception ex) { if (handleExceptions) { _loggerService.LogError(ex); } else { throw; } } } } return sentMailsCount; }
/// <summary> /// Takes a message and constructs an DSN for it. /// </summary> /// <param name="message">The message to send notification about.</param> /// <param name="from">MailAddress this notification is from</param> /// <param name="dsn">The dsn to create.</param> /// <returns>The DSN.</returns> public static DSNMessage CreateNotificationFor(Message message, MailAddress from, DSN dsn) { if (message == null) { throw new ArgumentNullException("message"); } if (from == null) { throw new ArgumentNullException("from"); } if (dsn == null) { throw new ArgumentNullException("dsn"); } // // Verify that the message is not itself an MDN! // if (message.IsMDN()) { throw new ArgumentException("Message is an MDN"); } string notifyTo = message.From.Value; DSNMessage statusMessage = new DSNMessage(notifyTo, from.ToString(), dsn); statusMessage.AssignMessageID(); statusMessage.SubjectValue = string.Format("{0}:{1}", "Rejected", message.SubjectValue); statusMessage.Timestamp(); return statusMessage; }
public MailMessage(string from, string to) { this.body = string.Empty; if (from == null) { throw new ArgumentNullException("from"); } if (to == null) { throw new ArgumentNullException("to"); } if (from == string.Empty) { throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "from" }), "from"); } if (to == string.Empty) { throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "to" }), "to"); } this.message = new Message(from, to); if (Logging.On) { Logging.Associate(Logging.Web, this, this.message); } }
public async Task<ActionResult> SendMail(MessageModel messageModel) { if (ModelState.IsValid) { //If message contains not nullable fields as null value //invalidate message and do not continue if (string.IsNullOrEmpty(messageModel.Name) || string.IsNullOrEmpty(messageModel.MailAddress) || string.IsNullOrEmpty(messageModel.Message)) return RedirectToActionPermanent("Index"); Log.Debug("A sent contact message received"); //Setup smtp var smtpClient = new SmtpClient(Host, Port); //Create new message record var message = new Message() { Name = messageModel.Name, Mail = messageModel.MailAddress, PhoneNumber = messageModel.MailAddress, Content = messageModel.Message, Time = DateTime.Now }; //login mail smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential(MailAddress, Password); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = SslEnabled; //Setting From , To and CC var mail = new MailMessage(); mail.From = new MailAddress(MailAddress); mail.To.Add(new MailAddress(MailAddress)); mail.Subject = string.Format("New message from {0}", messageModel.Name); mail.SubjectEncoding = Encoding.UTF8; var msg = string.Format("Mail from {0} <{1}>: \n\n{2}", messageModel.Name, messageModel.MailAddress, messageModel.Message); mail.Body = msg; mail.BodyEncoding = Encoding.UTF8; try { await smtpClient.SendMailAsync(mail); message.Status = MessageStatus.Success; } catch (Exception ex) { //If cannot send mail due to exception, log it and store //the message as fail in db Log.Error(ex,"Error while sending mail"); message.Status = MessageStatus.Fail; } MessageManager.Insert(message); Log.Info(string.Format("The contact request is saved with id:{0} and status:{1}",message.Id, message.Status)); } return RedirectToActionPermanent("Index"); }
public MailMessage() { message = new Message(); if(Logging.On)Logging.Associate(Logging.Web, this, message); string from = SmtpClient.MailConfiguration.Smtp.From; if (from != null && from.Length > 0) { message.From = new MailAddress(from); } }
public MailMessage(MailAddress from, MailAddress to) { if (from == null) throw new ArgumentNullException("from"); if (to == null) throw new ArgumentNullException("to"); message = new Message(from,to); }
public void Ensure_CreateMessage_supplies_correct_filename_to_attachments_when_supplied_with_data_stream() { Message msg = new Message("*****@*****.**", "*****@*****.**", "subject", "body"); msg.Attachments.Add(new MessageAttachment("Attachment.txt", "text/plain", GetTestData())); MailMessage mailMsg = _smtpSender.CreateMailMessage(msg); Assert.AreEqual(1, mailMsg.Attachments.Count, "Attachment count doesn't match"); Assert.AreEqual("Attachment.txt", mailMsg.Attachments[0].Name); }
public MailMessage(MailAddress from, MailAddress to) { if (from == null) throw new ArgumentNullException(nameof(from)); if (to == null) throw new ArgumentNullException(nameof(to)); _message = new Message(from, to); }
public void Ensure_CreateMessage_assigns_correct_mime_type_to_attachments_when_supplied_with_filename() { Message msg = new Message("*****@*****.**", "*****@*****.**", "subject", "body"); msg.Attachments.Add(new MessageAttachment("text/plain", _filename)); using(MailMessage mailMsg = _smtpSender.CreateMailMessage(msg)) { Assert.AreEqual(1, mailMsg.Attachments.Count, "Attachment count doesn't match"); Assert.AreEqual("text/plain", mailMsg.Attachments[0].ContentType.MediaType); } }
/// <summary> /// Takes a message and constructs an MDN for it. /// </summary> /// <param name="message">The message to send notification about.</param> /// <param name="from">MailAddress this notification is from</param> /// <param name="notification">The notification to create.</param> /// <returns>The MDN.</returns> public static NotificationMessage CreateNotificationFor(Message message, MailAddress from, Notification notification) { if (message == null) { throw new ArgumentNullException("message"); } if (from == null) { throw new ArgumentNullException("from"); } if (notification == null) { throw new ArgumentNullException("notification"); } // // Verify that the message is not itself an MDN! // if (message.IsMDN()) { throw new ArgumentException("Message is an MDN"); } string notifyTo = message.GetNotificationDestination(); if (string.IsNullOrEmpty(notifyTo)) { throw new ArgumentException("Invalid Disposition-Notification-To Header"); } string originalMessageID = message.IDValue; if (!string.IsNullOrEmpty(originalMessageID)) { notification.OriginalMessageID = originalMessageID; } if (!notification.HasFinalRecipient) { notification.FinalRecipient = from; } NotificationMessage notificationMessage = new NotificationMessage(notifyTo, from.ToString(), notification); notificationMessage.AssignMessageID(); string originalSubject = message.SubjectValue; if (!string.IsNullOrEmpty(originalSubject)) { notificationMessage.SubjectValue = string.Format("{0}:{1}", notification.Disposition.Notification.AsString(), originalSubject); } notificationMessage.Timestamp(); return notificationMessage; }
public void Send(Message msg) { if (String.IsNullOrWhiteSpace(msg.From)) { SmtpSection smtp = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; msg.From = smtp.From; } using (SmtpClient smtp = new SmtpClient()) { smtp.Send(msg.From, msg.To, msg.Subject, msg.Body); } }
public MailMessage(MailAddress from, MailAddress to) { this.body = string.Empty; if (from == null) { throw new ArgumentNullException("from"); } if (to == null) { throw new ArgumentNullException("to"); } this.message = new Message(from, to); }
public static bool SendMail(string fromMail, string[] toMails, string message, string title, UserCredential cr = null) { var service = GetGmailService(cr); var request = service.Users.Messages.List("me"); var msg = new Message(); string body = "To: " + String.Join(",", toMails) + "\n" + "Subject: " + title + "\n\n" + message; msg.Raw = EncodeTo64(body); var send = service.Users.Messages.Send(msg, fromMail); send.Execute(); return true; }
protected void sendEmail_Click(object sender, EventArgs e) { try { Message message = new Message("172.18.0.121"); /* message.message.From = new MailAddress("*****@*****.**", "The Kidnapper"); message.message.To.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/aliens.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/atlas.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/basic.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/knoll.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/linsanity.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/marilyn.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/minnesotafats.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/monk.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/nessy.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/outbreak.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/pokemon.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/shot.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/spoon.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/super.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/thinker.jpg"), "image/jpeg"); message.AddAttachmentFromFile(Server.MapPath(@"~/mktbbpic/winteriscoming.jpg"), "image/jpeg"); message.Subject = "It's almost punch time..."; */ message.message.From = new MailAddress("*****@*****.**", "Titan Orbitting Satellite Kupernicus 9-E Space-Weather Satellite...in Space"); message.message.To.Add(new MailAddress("*****@*****.**", "John 'Old Man' Klett")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.Bcc.Add(new MailAddress("*****@*****.**")); message.message.IsBodyHtml = true; StringBuilder messageBody = new StringBuilder(); messageBody.AppendLine(@"<p align=""center""><b><font size=""+2"">Geomagnetic Sudden Impulse and Supernova Warning!!!!</font></b></p><p align=""left""><b><font size=""+1"">WARNING: Geomagnetic Sudden Impulse and/or Supernova expected</font></b></p><blockquote><p><b>Space-Weather Satellite Message Code: JUSTINBIEBER<br> Serial Number: 001-0945712-b-hippo<br> Issue Time: 2012 Apr 19 1930 UTC</b> </p> <p><b>WARNING: Geomagnetic Sudden Impulse and/or Supernova expected<br> Valid From: 2012 Apr 19 1650 UTC<br> Valid To: 2012 Apr 20 1730 UTC<br> </p> </blockquote> <p align=""left""><font size=""+1""><b>SUMMARY: Geomagnetic Sudden Impulse and/or Supernova</b></font></p> <blockquote> <p><b>Space-Weather Satellite Message Code: JUSTINBIEBERSUM<br> Serial Number: 001-0945712-b-hippo<br> Issue Time: 2012 Apr 19 1930 UTC</b> </p> <p><b>SUMMARY: Geomagnetic Sudden Impulse and/or Supernova expected<br> Event to be localized to the Wilmington, DE area. Please update all digital screens immediately to relay information to the passenger(s).<br>Small children, cats, dogs, elderly people, and pregnant women should be abandoned at once. Head indoors imediately.</p></blockquote>"); message.Body = messageBody.ToString(); message.SendEmail(); } catch (Exception ex) { WebCommon.LogExceptionInfo(ex); Response.Write("Error"); } }
public MailMessage() { this.body = string.Empty; this.message = new Message(); if (Logging.On) { Logging.Associate(Logging.Web, this, this.message); } string from = SmtpClient.MailConfiguration.Smtp.From; if ((from != null) && (from.Length > 0)) { this.message.From = new MailAddress(from); } }
public MailMessage(string from, string to) { if (from == null) throw new ArgumentNullException("from"); if (to == null) throw new ArgumentNullException("to"); if (from == String.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"from"), "from"); if (to == String.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"to"), "to"); message = new Message(from,to); if(Logging.On)Logging.Associate(Logging.Web, this, message); }
public MailMessage(string from, string to) { if (from == null) throw new ArgumentNullException(nameof(from)); if (to == null) throw new ArgumentNullException(nameof(to)); if (from == string.Empty) throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(from)), nameof(from)); if (to == string.Empty) throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(to)), nameof(to)); _message = new Message(from, to); if (WebEventSource.Log.IsEnabled()) WebEventSource.Log.Associate(this, _message); }
public void TestAttachmentEncoding() { string[] testFiles = GetTestFiles(); SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test"); foreach (string testFile in testFiles) { Trace.WriteLine(testFile); string fileHash = TestSetup.GetFileHash(testFile); var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Test"; mail.Attachments.Add(new Attachment(testFile)); TestSetup.SendMessage(mail); POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1); var sim = new POP3Simulator(); sim.ConnectAndLogon("*****@*****.**", "test"); string fileContent = sim.RETR(1); sim.DELE(1); sim.QUIT(); var message = new Message(); try { File.WriteAllText(message.Filename, fileContent); message.RefreshContent(); message.Attachments[0].SaveAs(message.Filename); string fileHashAfter = TestSetup.GetFileHash(message.Filename); Assert.AreEqual(fileHash, fileHashAfter); } finally { File.Delete(message.Filename); } } }
public void NoReceipient() { var attachmentFactory = new Mock<IMailAttachmentFactory>(); var notifier = new Mock<IMessageDispatchNotifier>(); Exception ex = null; notifier.Setup(x => x.Notify(It.IsAny<IMessage>(), false, It.IsAny<Exception>())) .Callback<IMessage, bool, Exception>((x, y, z) => ex = z); var dispatcher = new MailMessageDispatcher(attachmentFactory.Object, notifier.Object); var message = new Message(); dispatcher.Send(message); Assert.AreEqual(0, smtpServer.ReceivedEmailCount, "Count differs"); Assert.IsNotNull(ex); Assert.AreEqual("A recipient must be specified.", ex.Message); }
/// <summary> /// Extract DSN from a message /// </summary> /// <param name="message"><see cref="Health.Direct.Common.Mail.Message"/></param> /// <returns><see cref="Notification"/>object</returns> public static DSN Parse(Message message) { if (message == null) { throw new ArgumentNullException("message"); } if (!message.IsDSN()) { throw new DSNException(DSNError.NotDSN); } if (!message.IsMultiPart) { throw new MDNException(MDNError.InvalidMDNBody); } return Parse(message.GetParts()); }
public void Send() { var attachmentFactory = new Mock<IMailAttachmentFactory>(); var notifier = new Mock<IMessageDispatchNotifier>(); var dispatcher = new MailMessageDispatcher(attachmentFactory.Object, notifier.Object); var source = new TextAttachment { Name = "Text", Content = "Content" }; var attachment = new Attachment(new MemoryStream(Encoding.ASCII.GetBytes("Content")), "Test"); attachmentFactory.Setup(x => x.CreateAttachement(It.IsAny<IAttachment>())).Returns(attachment); var message = new Message { From = "*****@*****.**", FromName = "From", BounceAddress = "*****@*****.**", Subject = "Subject", Text = "Text", Html = "Html", }; message.ToAddress.Add("*****@*****.**"); message.Cc.Add("*****@*****.**"); message.Bcc.Add("*****@*****.**"); message.Headers["X-Path"] = "xpath"; message.Attachments.Add(source); dispatcher.Send(message); Assert.AreEqual(1, smtpServer.ReceivedEmailCount, "Count differs"); notifier.Verify(x => x.Notify(It.IsAny<IMessage>(), true, null)); var candidate = smtpServer.ReceivedEmail.First(); Assert.AreEqual("Subject", candidate.Subject, "Subject differs"); }
public void SendEmail(User user, string subject, string text) { var msg = new AE.Net.Mail.MailMessage { Subject = subject, Body = text, From = new MailAddress(config.NotificationAccount) }; msg.To.Add(new MailAddress(user.Email)); msg.ReplyTo.Add(msg.From); // Bounces without this!! var msgStr = new StringWriter(); msg.Save(msgStr); var m = new Message { Raw = Base64UrlEncode(msgStr.ToString()) }; gmailService.Value.Users.Messages.Send(m, "me").Execute(); }
private bool AddToDataBase(MessageMdelApp model) { try { Message a = new Message() { Name = model.Name, Email = model.Email, Message1 = model.Msg }; context.Messages.Add(a); context.SaveChanges(); return true; } catch (Exception er) { ClassLog.Write("Ошибка создания элемента БД", er); return false; } }
/// <summary> /// Sends the jmail. /// </summary> /// <param name="from">From.</param> /// <param name="address">The address.</param> /// <param name="title">The title.</param> /// <param name="bodyhtml">The bodyhtml.</param> /// <param name="encode">The encode.</param> /// <param name="user">The user.</param> /// <param name="pwd">The PWD.</param> /// <returns></returns> public static bool SendJmail(string from, string address, string title, string bodyhtml, System.Text.Encoding encode, string user, string pwd) { Dimac.JMail.Message message = new Message(); message.From = from; var addressArray = address.Split(','); foreach (var item in addressArray) { message.To.Add(item); } message.Subject = title; message.Charset = encode; message.BodyHtml = bodyhtml; try { Smtp.Send(message, "smtp.exmail.qq.com", 25, "smtp.exmail.qq.com", SmtpAuthentication.Login, user, pwd); return true; } catch { return false; } }
/// <summary> /// Sendmails the specified from. /// </summary> /// <param name="from">From.</param> /// <param name="address">The address.</param> /// <param name="subject">The title.</param> /// <param name="bodyhtml">The bodyhtml.</param> /// <returns></returns> public static bool SendJmail(string from, string address, string subject, string bodyhtml) { Dimac.JMail.Message message = new Message(); message.From = from; message.To.Add(address); message.Subject = subject; message.Charset = System.Text.Encoding.GetEncoding("gb2312"); message.BodyHtml = bodyhtml; try { Smtp.Send(message, "smtp.exmail.qq.com", 25, "smtp.exmail.qq.com", SmtpAuthentication.Login, "*****@*****.**", "Miaow@2010"); return true; } catch { return false; } }
abstract public void Write(Message cMessage);
static public void Wait(Message cMessage) { cMessage._cMRE = new System.Threading.ManualResetEvent(false); _aqMessagesQueue.Enqueue(cMessage); cMessage._cMRE.WaitOne(); }
public MailMessage() { _message = new Message(); if (WebEventSource.Log.IsEnabled()) WebEventSource.Log.Associate(this, _message); }
/// <summary> /// Prepares the body (by replacing the param values) and sends an email to the user subscribed to a topic /// </summary> /// <param name="body">Base body of the email.</param> private void SendEmailToSubscriptor(Message topicMessage, User user, string body, string url, string unsubscribeUrl) { if (user.Guid == Guid.Empty) { throw new ArgumentException("User.Guid cannot be empty."); } unsubscribeUrl = String.Format(unsubscribeUrl, user.Id, user.Guid.ToString("N")); MailMessage message = new MailMessage(); message.To.Add(new MailAddress(user.Email, user.UserName)); message.IsBodyHtml = true; #region Replace body values body = Utils.ReplaceBodyValues(body, user, new[] { "UserName" }); body = Utils.ReplaceBodyValues(body, topicMessage.Topic, new[] { "Title", "Id" }); body = Utils.ReplaceBodyValues(body, new Dictionary<string, string>() { { "unsubscribeUrl", unsubscribeUrl }, { "url", url } }); body = Utils.ReplaceBodyValues(body, new Dictionary<string, string>() { { "body", message.Body } }); #endregion message.Body = body; message.Subject = "Re: " + topicMessage.Topic.Title; SendMail(message); }
private void Write(bool bSync, Message cMessage) { #if LOGGER_OFF return; #endif if (_eLevelMinimum > cMessage.eLevel) { cMessage.Done(); return; } if (bSync) Message.Wait(cMessage); else _aqMessagesQueue.Enqueue(cMessage); }