Example #1
0
 /// <summary>
 /// Creates a new Email instance and sets the from
 /// property
 /// </summary>
 /// <param name="emailAddress">Email address to send from</param>
 /// <param name="name">Name to send from</param>
 /// <returns>Instance of the Email class</returns>
 public static Email From(string emailAddress, string name = "")
 {
     var email = new Email
                     {
                         Message = {From = new MailAddress(emailAddress, name)}
                     };
     return email;
 }
Example #2
0
		public void New_SplitAddress_Test2()
		{
			var email = new Email()
				.To("[email protected]; [email protected]", "James 1");

			Assert.AreEqual(2, email.Message.To.Count);
			Assert.AreEqual("*****@*****.**", email.Message.To[0].Address);
			Assert.AreEqual("*****@*****.**", email.Message.To[1].Address);
			Assert.AreEqual("James 1", email.Message.To[0].DisplayName);
			Assert.AreEqual(string.Empty, email.Message.To[1].DisplayName);
		}
Example #3
0
		public void New_Callback_Method_Is_Called_On_Cancel()
		{
			string toEmail = "*****@*****.**";
			string fromEmail = "*****@*****.**";
			string subject = "sup dawg";
			string body = "what be the hipitity hap?";

			var email = new Email(new SmtpClient("localhost", 25), fromEmail)
				//.From(fromEmail)
				.To(toEmail)
				.Subject(subject)
				.Body(body)
				//.UsingClient(new SmtpClient("localhost", 25))
				.SendAsync(MailDeliveryComplete);

			email.Cancel();

			updatedEvent.WaitOne();

			Assert.IsTrue(callbackCalled);
		}
		public void New_Does_Not_Cause_An_Exception_If_SmtpClient_Is_Null()
		{
			SmtpClient smtpClient = null;
			var email = new Email(smtpClient, FromEmail);
			email.Dispose();
		}
		public void New_Does_Not_Cause_An_Exception_If_Message_Is_Null()
		{
			var email = new Email(new FakeSmtpClient(), FromEmail);

			email.Message = null;

			email.Dispose();
		}
		public void New_Disposes_Of_The_SmtpClient()
		{
			var smtpClient = new FakeSmtpClient();
			var email = new Email(smtpClient, FromEmail);
			
			email.Dispose();

			Assert.IsTrue(smtpClient.DisposeHasBeenCalled);
		}
		public void New_Disposes_Of_The_Message()
		{
			var email = new Email(new FakeSmtpClient(), FromEmail);
			
			var mailMessage = new FakeEmailMessage();

			email.Message = mailMessage;

			email.Dispose();

			Assert.IsTrue(mailMessage.DisposeHasBeenCalled);
		}
		public void New_Email_Implements_IDisposable()
		{
			var email = new Email("*****@*****.**");

			Assert.IsInstanceOfType(email, typeof(IDisposable));

			//Assert.AreEqual(replyEmail, email.Message.ReplyToList.First().Address);
		}
		public void New_Is_Valid_With_Properties_Set()
		{
			var email = new Email(fromEmail)
				.To(toEmail)
				.Subject(subject)
				.Body(body);

			Assert.AreEqual(body, email.Message.Body);
			Assert.AreEqual(subject, email.Message.Subject);
			Assert.AreEqual(fromEmail, email.Message.From.Address);
			Assert.AreEqual(toEmail, email.Message.To[0].Address);
		}
		public void New_Can_Add_Multiple_BCCRecipients_From_List()
		{
			var emails = new List<MailAddress>();
			emails.Add(new MailAddress("*****@*****.**"));
			emails.Add(new MailAddress("*****@*****.**"));

			var email = new Email(fromEmail)
				.BCC(emails);

			Assert.AreEqual(2, email.Message.Bcc.Count);
		}
		public void New_Can_Add_Multiple_Recipients()
		{
			string toEmail1 = "*****@*****.**";
			string toEmail2 = "*****@*****.**";

			var email = new Email(fromEmail)
				.To(toEmail1)
				.To(toEmail2);

			Assert.AreEqual(2, email.Message.To.Count);
		}
		public void New_Body_Is_Set()
		{
			var email = new Email(fromEmail)
				.Body(body);

			Assert.AreEqual(body, email.Message.Body);
		}
		public void New_Subject_Is_Set()
		{
			var email = new Email(fromEmail)
				.Subject(subject);

			Assert.AreEqual(subject, email.Message.Subject);
		}
		public void New_From_Address_Is_Set()
		{
			var email = new Email(fromEmail);

			Assert.AreEqual(fromEmail, email.Message.From.Address);
		}
		public void New_To_Address_Is_Set()
		{
			var email = new Email(fromEmail)
				.To(toEmail);

			Assert.AreEqual(toEmail, email.Message.To[0].Address);
		}
Example #16
0
        public static void NotifyRecruiter(Models.JobApplication entity, string cvFolder)
        {
            // Save in Mails folder for sending later
            
            //E:\Work\AngJobs.com\src\Angjobs\Angjobs\Assets\bootstrap\css\bootstrap-theme.css
            //E:\Work\AngJobs.com\src\Angjobs\Angjobs\Assets\bootstrap\css\bootstrap.min.css
            //E:\Work\AngJobs.com\src\Angjobs\Angjobs\Assets\styles\styles.css
            var template = new StringBuilder();
            template.AppendLine(@"<html>");
            template.AppendLine(@"<style>");

                template.AppendLine(@"     .bg-light {                  ");
                template.AppendLine(@"    color: #58666e;               ");
                template.AppendLine(@"    background-color: #edf1f2;    ");
                template.AppendLine(@"    }                             ");
                template.AppendLine(@"    .label {                      ");
                template.AppendLine(@"        display: inline;          ");
                template.AppendLine(@"        padding: .2em .6em .3em;  ");
                template.AppendLine(@"        font-size: 75%;           ");
                template.AppendLine(@"        font-weight: bold;        ");
                template.AppendLine(@"        line-height: 1;           ");
                template.AppendLine(@"        color: #fff;              ");
                template.AppendLine(@"        text-align: center;       ");
                template.AppendLine(@"        white-space: nowrap;      ");
                template.AppendLine(@"    }                             ");
                template.AppendLine(@"    dl {                          ");
                template.AppendLine(@"        margin-top: 0;            ");
                template.AppendLine(@"        margin-bottom: 20px;      ");
                template.AppendLine(@"    }                             ");
                template.AppendLine(@"    dt {                          ");
                template.AppendLine(@"      font-weight: bold;          ");
                template.AppendLine(@"    }                             ");
                template.AppendLine(@"    dt, dd {                      ");
                template.AppendLine(@"        line-height: 1.42857143;  ");
                template.AppendLine(@"    }                             ");
                template.AppendLine(@"    p {                             ");
                template.AppendLine(@"        margin: 0 0 10px;           ");
                template.AppendLine(@"    }                               ");

          
            template.AppendLine(    @"</style>");
            template.AppendLine(@"<body>");
            
            template.AppendLine("Hello @Model.Name,");
            template.AppendLine(@"<br/>");
            template.AppendLine(@"<br/>");
            template.AppendLine(@"@Model.Applicant applied for a <a href='@Model.JobLink' target='_blank'>job</a> you advertised recently.");

            if (!string.IsNullOrEmpty(entity.ApplicantMessage))
                template.AppendLine(@" Below is the candidate's resume:");
            template.AppendLine(@"<br/>");
            template.AppendLine(@"<br/>");
            template.Append(@entity.ApplicantMessage);

            template.AppendLine(@"</body>");
            template.AppendLine(@"</html>");

            string htmlBody = template.ToString();


            var result = PreMailer.Net.PreMailer.MoveCssInline(htmlBody);

            htmlBody = result.Html;

               // result.Html   

            string fromEmail = ParseEmail(entity.ApplicantEmail);
            if(!string.IsNullOrEmpty(fromEmail))
            {
                var message = new MailMessage() { IsBodyHtml = true };
                Attachment attachment = getAttachment(entity.CV, cvFolder);
                var attachments = new List<Attachment>();
                if (attachment != null)
                    attachments.Add(attachment);

                //TODO make sure there is a valid destination email
                string destEmail = entity.JobPost.JobEmail ?? "*****@*****.**";
                var email = new Email(fromEmail)
                    .To(destEmail)
                    .Subject(subject + entity.ApplicantEmail + "applied for " + entity.JobPost.JobTitle)
                    .UsingTemplate(htmlBody, new
                    {
                        Name = entity.JobPost.ContactName,
                        Applicant = entity.ApplicantEmail, // TODO Actually it includes the name as well
                        JobLink = "http://angjobs.com/#!/jobdetails/"+ entity.JobPost.Id
                    }, true)
                    .BodyAsHtml()
                    .ReplyTo(fromEmail)
                    .Attach(attachments);
                
                object fileAttachment = attachment;

                email.SendAsync(SendCompletedEventHandler_NotifyRecruiter, fileAttachment);
            }
        }
Example #17
0
        public void ProcessQueueProductEmail(string subscriberId)
        {
            _currentSubscription = _bus.SubscribeAsync <ProductMailQueueDto>(subscriberId, pmq =>
            {
                return(Task.Factory.StartNew(() =>
                {
                    var _productMailQueueRepositoryLocal =
                        ServiceLocator.Current.GetInstance <IMercuritusFullDomainRepository <ProductMailQueue> >();

                    var _userRepositoryLocal =
                        ServiceLocator.Current.GetInstance <IMercuritusFullDomainRepository <User> >();

                    var _unitWorkLocal =
                        ServiceLocator.Current.GetInstance <IMercuritusFullDomainUnitOfWork>();

                    Check.Require(pmq.ProductMailQueueID > 0, "productMailQueueId must be positive");

                    var productMailQueueToProcess = _productMailQueueRepositoryLocal.DbSet.Where(
                        x => x.ProductMailQueueID == pmq.ProductMailQueueID && x.Activate == true).FirstOrDefault();

                    Check.Require(productMailQueueToProcess != null, "productMailQueueId must be valid");
                    Check.Require(productMailQueueToProcess.QueueStatusID == (int)QueueStatusEnum.CREATED, "productMailQueue must be in CREATED mode");

                    try
                    {
                        var now = DateTime.Now;
                        productMailQueueToProcess.Message = "Processing...";
                        productMailQueueToProcess.ModifiedOn = now;
                        productMailQueueToProcess.QueueStatusID = (int)QueueStatusEnum.PROCESSING;
                        _productMailQueueRepositoryLocal.Update(productMailQueueToProcess);
                        _unitWorkLocal.Commit();

                        var p = productMailQueueToProcess.Product;
                        Check.Require(p.UserID.HasValue, "product must be assigned to a user, for email adress");
                        var u = _userRepositoryLocal.GetById(p.UserID.Value);
                        var template = productMailQueueToProcess.MailerTemplate;

                        var m = new FluentEmail.Email("*****@*****.**", "Mendeo - No Reply")
                                .To(u.EMail)
                                .Subject(template.Subject)
                                .UsingTemplate(template.Body, p, template.IsHtml);

                        m.Send();

                        var nowSent = DateTime.Now;
                        productMailQueueToProcess.Message = "Sent...";
                        productMailQueueToProcess.ModifiedOn = nowSent;
                        productMailQueueToProcess.QueueStatusID = (int)QueueStatusEnum.SUCCESS;
                        _productMailQueueRepositoryLocal.Update(productMailQueueToProcess);
                    }
                    catch (Exception e)
                    {
                        var nowError = DateTime.Now;
                        productMailQueueToProcess.Message = e.Message;
                        productMailQueueToProcess.ModifiedOn = nowError;
                        productMailQueueToProcess.QueueStatusID = (int)QueueStatusEnum.ERROR;
                        _productMailQueueRepositoryLocal.Update(productMailQueueToProcess);
                    }
                    finally
                    {
                        _unitWorkLocal.Commit();
                    }
                }));
            });
        }
		public void New_ReplyTo_Address_Is_Set()
		{
			var replyEmail = "*****@*****.**";

			var email = new Email(fromEmail)
				.ReplyTo(replyEmail);

			Assert.AreEqual(replyEmail, email.Message.ReplyToList.First().Address);
		}