示例#1
0
        public async Task ReplyToAsync(string serverPath, int port, string email, string password, MimeMessage messageToReply, bool replyToAll, string answer, ICollection <IFormFile> attachments = null, ICollection <string> cc = null, ICollection <string> bcc = null)
        {
            var sendedAtachments = await ConvertFormFilesToSendedAttachments(attachments);

            var messageToSend = await ReplyTo(messageToReply, email, true, answer, sendedAtachments, cc, bcc);

            await _emailClientFactory.SendAsync(email, password, serverPath, port, messageToSend);
        }
        public async Task SendAsync(int userId, string from, ICollection <string> to, ICollection <string> cc, ICollection <string> bcc, string subject, string textHtmlBody, ICollection <IFormFile> attachments = null)
        {
            var emailAccountWithSmtpSettings = await _emailAccountRepository.GetByUserIdAndByEmailWithSmtpAsync(userId, from, false);

            if (emailAccountWithSmtpSettings == null || emailAccountWithSmtpSettings.Smtp == null)
            {
                throw new Exception("Email account with this ids does not exist.");
            }
            var sendedEmailMessage = new SendedEmailMessage(from, to, subject, textHtmlBody, emailAccountWithSmtpSettings);
            ICollection <SendedAtachment> sendedAttachments = null;

            if (attachments != null && attachments.Count > 0)
            {
                sendedAttachments = await ConvertFormFilesToSendedAttachments(attachments);

                sendedEmailMessage.AddSendedAtachments(sendedAttachments);
            }
            await _emailClientFactory.SendAsync(emailAccountWithSmtpSettings.Email, emailAccountWithSmtpSettings.Password, emailAccountWithSmtpSettings.Smtp.Host, emailAccountWithSmtpSettings.Smtp.Port, emailAccountWithSmtpSettings.User.Name, to, cc, bcc, subject, textHtmlBody, sendedAttachments);

            await _sendedEmailMessageRepository.AddAsync(sendedEmailMessage);
        }