private SendEmailInfo CreateSendEmailInfo() { SendEmailInfo info = null; var userInfo = Config <UserInfoConfig> .Current; String from = userInfo.EmailAddress; String title = this._tbEmailTitle.Text.Trim(); String to = this._tbRecevicer.Text.Trim(); String textBody = this._tbTextBody.Text.Trim(); if (String.IsNullOrEmpty(from)) { return(null); } if (String.IsNullOrEmpty(title)) { return(null); } if (String.IsNullOrEmpty(to)) { return(null); } var attachmentInfos = this._lbSendAttachments.AttachmentInfos; info = new SendEmailInfo(); info.From = from; info.To = to; info.Title = title; info.TextBody = textBody; info.AttachmentInfos = attachmentInfos; return(info); }
public async Task SendEmailAsync(SendEmailInfo emailInfo) { if (emailInfo == null) { return; } await Task.Run(() => { this.SendEmail(emailInfo); }); }
public void SendEmail(SendEmailInfo emailInfo) { SmtpClient oSmtp = new SmtpClient(); SmtpServer oServer = new SmtpServer(SendMailServerAddress); oServer.User = this.User; oServer.Password = this.Password; oServer.Port = 465; oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; if (emailInfo.IsRespectivelySend) { foreach (var attach in emailInfo.AttachmentInfos) { SmtpMail oMail = new SmtpMail(LicenseCode); oMail.From = emailInfo.From; oMail.To = attach.ReceiverEmail; String subject = Path.GetFileNameWithoutExtension(attach.Name); oMail.Subject = subject; oMail.TextBody = subject; oMail.AddAttachment(attach.SavePath); oSmtp.SendMail(oServer, oMail); } } else { SmtpMail oMail = new SmtpMail(LicenseCode); oMail.From = emailInfo.From; oMail.To = emailInfo.To; oMail.Subject = emailInfo.Title; oMail.TextBody = emailInfo.TextBody; if (emailInfo.AttachmentInfos.Count > 0) { foreach (var info in emailInfo.AttachmentInfos) { oMail.AddAttachment(info.SavePath); } } oSmtp.SendMail(oServer, oMail); } }