public SendResult Send(JMessage msg) { using (var resFileService = SiteManager.Get <ResourceFileService>()) { string sendto = String.Join(";", msg.SendToIds.Select(s => AppManager.Instance.UserManager.GetById(s.ToString())) .Where(u => !u.Email.IsEmpty()) .Select(u => (u.Name + "<" + u.Email + ">"))); var fromUser = AppManager.Instance.UserManager.GetById(msg.SenderId.ToString()); string from = fromUser == null ? null : fromUser.Email; string ccto = String.Join(";", msg.CopyToIds.Select(s => AppManager.Instance.UserManager.GetById(s.ToString())) .Where(u => !u.Email.IsEmpty()) .Select(u => (u.Name + "<" + u.Email + ">"))); SMTPMail mail = new SMTPMail(from, sendto, ccto, msg.Title, msg.Content, resFileService.GetFilePath((msg.AttachmentIds ?? new int[0]).ToArray())); mail.Send(); SendResult result = new SendResult { FailedReason = mail.ErrorMessage, MessageId = msg.Id, SentTime = DateTime.Now, PlanSendTime = msg.PlanSendTime, }; if (!mail.ErrorMessage.IsEmpty()) { result.FailedIds = msg.SendToIds.Union(msg.CopyToIds); } return(result); } }
public void SendMail() { SMTPMail mail = new SMTPMail("*****@*****.**", "Hello myself", "test send mail to my self"); mail.Send(); Debug.WriteLine("The Return Message Is: " + mail.ErrorMessage); Assert.IsTrue(mail.ErrorMessage.IsEmpty()); }
public virtual LoginState SendPasswordResetMessage(string userName, string email, string resetUrl) { var _context = new ModelContext(); MemberShip member = _context.Set <MemberShip>().FirstOrDefault(m => m.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) && m.IsConfirmed == true); if (member == null) { return(LoginState.UserNotExist); } if (!member.Email.Equals(email, StringComparison.OrdinalIgnoreCase)) { return(LoginState.EmailError); } member.ConfirmationToken = CommOp.NewId(); string url = resetUrl + "?username="******"&confirmToken=" + member.ConfirmationToken; string subject = ResHelper.GetStr("Password+Reset"); string body = "<p>" + ResHelper.GetStr("Click the link below to reset your password") + "</p>" + "<p>" + "<a href='" + url + "' target='_blank'>" + url + "</a></p>"; SMTPMail mail = new SMTPMail(member.Email, subject, body); _context.SaveChanges(); mail.Send(); if (mail.ErrorMessage.IsEmpty()) { return(LoginState.OK); } else { #if DEBUG if (HttpContext.Current != null) { HttpContext.Current.Session["ResetPasswordEmailBody"] = body; } #endif return(LoginState.EmailSendError); } }