public static bool Send(MailMessage mail) { try { SmtpClientEmailSender sces = new SmtpClientEmailSender(new log4netProvider()); string attachments = ""; if (mail.Attachments.Count > 0) { for (int i = 0; i < mail.Attachments.Count; i++) { attachments += mail.Attachments[i].ToString() + ";"; } if (attachments.EndsWith(";")) { attachments = attachments.Substring(0, attachments.Length - 1); } } return(sces.SendMail (mail.To, mail.Cc, mail.Bcc, "", mail.Subject, mail.Body, attachments, true, System.Net.Mail.MailPriority.Normal)); } catch (Exception ex) { new log4netProvider().Log(ex); return(false); } }
private void SendEmailForUploading(int projectId, int userId, string fileDescription, string filePath) { if (projectId == 0) { return; } UserApplication userApp = new UserApplication(); ProjectApplication projectApp = new ProjectApplication(); UsersEntity usersEntity = userApp.GetUser(userId); //发邮件的角色必须是Client或PM if (usersEntity.Role != RolesEnum.CLIENT && usersEntity.Role != RolesEnum.PM && usersEntity.Status == Status.Active.ToString().ToUpper()) { return; } ProjectsEntity projectEntity = projectApp.Get(projectId); IEmailSender smtpClient = new SmtpClientEmailSender(new TextFileLogger()); //邮件参数初始化 string contentTemplete = GetEmailTemplate("SendEmailToCilentAndPMWhenUploading.txt").Trim(); if (!string.IsNullOrEmpty(contentTemplete)) { contentTemplete = contentTemplete.Replace("[UploadUser]", usersEntity.FirstName) .Replace("[ProjectTitle]", projectEntity.Title) .Replace("[DateTime]", DateTime.Now.ToString("MM/dd/yyyy HH:mm")) .Replace("[FileDescription]", fileDescription) .Replace("[FilePath]", filePath); } string to = string.Empty; string subject = string.Format("Notice - {0} uploaded a file or some files ", usersEntity.FirstName); List <int> userIdList = projectApp.GetActiveUserIdByProjectId(projectId); if (userIdList != null && userIdList.Count > 0) { userIdList.RemoveAll(o => o == userId); foreach (int item in userIdList) { var userItem = userApp.GetUser(item); if (userItem.Role == RolesEnum.CLIENT || userItem.Role == RolesEnum.PM) { to = userItem.Email; if (!string.IsNullOrEmpty(contentTemplete)) { string content = contentTemplete.Replace("[FirstName]", userItem.FirstName) .Replace("[LastName]", userItem.LastName); smtpClient.SendMail(to, subject, content, false, MailPriority.Normal); } } } } }