コード例 #1
0
        public async Task<SendEmailDomain> SendEmailAsync(SendEmailDomain email)
        {
            string emailAddress = email.Address;
            string emailDisplayName = email.DisplayName;

            // Send email
            var emailToSend = new Email(email.Subject, email.Body, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName));
            emailToSend.To.Add(new EmailAddress(email.Emails.First(), emailDisplayName)); //Email must always have a valid recipient
            emailToSend.Headers.AddRange(email.Emails); // Must always add to headers for utilizing send-grid api

            await _mailerRepository.SendMail(emailToSend);

            return email;
        }
コード例 #2
0
ファイル: EmailTest.cs プロジェクト: GusLab/video-portal
 public void CreateEmailTest()
 {
     //Arrange
     const string content = "content";
     const string contentType = "contentType";
     const string subject = "subject";
     var from = new EmailAddress();
     
     //Act
     var email = new Email(subject, content, contentType, from);
     
     //Assert
     Assert.IsNotNull(email.To);
     Assert.IsNotNull(email.Cc);
     Assert.IsNotNull(email.Bcc);
     Assert.AreEqual(subject,email.Subject);
     Assert.AreEqual(content, email.Content);
     Assert.AreEqual(contentType, email.ContentType);
     Assert.AreEqual(from, email.From);
 }
コード例 #3
0
        public async Task<SendEmailDomain> SendAndLogEmailAsync(SendEmailDomain email)
        {
            string emailAddress = email.Address;
            string emailDisplayName = email.DisplayName;

            // Send email
            var emailToSend = new Email(email.Subject, email.Body, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName));
            emailToSend.To.Add(new EmailAddress(email.Emails.First(), emailDisplayName)); //Email must always have a valid recipient
            emailToSend.Headers.AddRange(email.Emails); // Must always add to headers for utilizing send-grid api

            await _mailerRepository.SendMail(emailToSend);

            email.Id = ((int)email.Template) + GetUtcTimestamp();
            email.Created = DateTime.UtcNow;

            // Log sent email
            SendEmailEntity entity = _mapper.Map<SendEmailDomain, SendEmailEntity>(email);
            await _sendEmailRepository.AddAsync(entity);

            return email;
        }
コード例 #4
0
        private Email ComposeRecoveryMail(PasswordRecoveryEntity recoveryEntity, string userName, string link)
        {
            string emailAddress = _settings.EmailAddressAlerts;
            string emailDisplayName = Emails.SenderDisplayName;
            string emailSubject = Emails.SubjectPasswordRecovery;
            string emailTemplate = PortalResources.UserRecovery;
            string emailBody = String.Format(emailTemplate, userName, link);

            var result = new Email(emailSubject, emailBody, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName));
            result.To.Add(new EmailAddress(recoveryEntity.Email, recoveryEntity.Email));

            return result;
        }