Exemplo n.º 1
0
        public static bool SendEmail(EmailEnvelop emailEnvelop, EmailConfig emailConfig)
        {
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient(emailConfig.Smtp);

                mail.From = new MailAddress(emailEnvelop.From);
                mail.To.Add(emailEnvelop.To);
                mail.Subject = emailEnvelop.Subject;

                mail.IsBodyHtml = true;
                mail.Body       = emailEnvelop.Body;

                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.EnableSsl             = true;
                SmtpServer.Port           = emailConfig.Port;
                SmtpServer.Credentials    = new System.Net.NetworkCredential(emailConfig.UserName, emailConfig.Password);
                SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;

                SmtpServer.Send(mail);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task SendEmailAsync(EmailEnvelop emailEnvelop, EmailOptions emailOptions = null)
        {
            if (emailOptions == null)
            {
                emailOptions = _emailOptions.CurrentValue;
            }

            if (emailOptions.SkipMode)
            {
                return;
            }

            var client = new SmtpClient(emailOptions.Host, emailOptions.Port)
            {
                Credentials = new NetworkCredential(emailOptions.UserName, emailOptions.Password),
                EnableSsl   = emailOptions.EnableSSL
            };

#pragma warning disable CA2000 // Dispose objects before losing scope
            await client.SendMailAsync(
                new MailMessage(emailOptions.From, emailEnvelop?.To, emailEnvelop.Subject, emailEnvelop.Body)
                { IsBodyHtml = true }
                ).ConfigureAwait(false);

#pragma warning restore CA2000 // Dispose objects before losing scope

            client.Dispose();
        }
Exemplo n.º 3
0
        public bool EmailRentValuationReport(HOBAppUser user, decimal homeOwnerSpecifiedRent)
        {
            string            userId = this.leadDataManager.GetUserIdFromEmail(user.Email);
            string            updatedRentValuationRecord = this.leadDataManager.UpdateHomeOwnerSpecifiedRent(userId, homeOwnerSpecifiedRent);
            RentValuationData rentValuationData          = this.leadDataManager.FindRentValuationRecord(updatedRentValuationRecord);
            Address           address = this.leadDataManager.GetAddressFromRentValuationRecordId(updatedRentValuationRecord);

            //var jsonUser = JsonConvert.SerializeObject(user);
            //var jsonRentValuationData = JsonConvert.SerializeObject(rentValuationData);
            //var jsonAddress = JsonConvert.SerializeObject(address);

            EmailEnvelop emailEnvelope = new EmailEnvelop()
            {
                Body = "<h1>Congratulations on your signup!</h1>"
                       + "<hr/>"
                       + "<h2>Here is the data we have collected from you.</h2>"
                       + "<h3>User Info</h3>"
                       + "<p> Name: " + user.FirstName + " " + user.LastName + "</p>"
                       + "<p> IP Address: " + user.ClientIPAddress + "</p>"
                       + "<p> Phone: " + user.Phone + "</p>"
                       + "<h3>Rent Valuation Data</h3>"
                       + "<p> Home Owner Specified Rent: " + (rentValuationData.HomeOwnerSpecifiedRent == 0 ? "None" : rentValuationData.HomeOwnerSpecifiedRent.ToString()) + "</p>"
                       + "<p> Average Monthly Rent: " + rentValuationData.AverageMonthlyRent + "</p>"
                       + "<p> Valuation Range High : " + rentValuationData.ValuationRentHigh + "</p>"
                       + "<p> Valuation Range Low : " + rentValuationData.ValuationRentLow + "</p>"
                       + "<p> Value Changed In 30 Days: " + rentValuationData.ValueChangedIn30Days + "</p>"
                       + "<p> Is Rent Estimate Available: " + (rentValuationData.IsRentEstimateAvailable?"Yes":"No") + "</p>"
                       + "<h3>Home Address</h3>"
                       + "<p> Street: " + address.Street + "</p>"
                       + "<p> City: " + address.City + "</p>"
                       + "<p> County: " + (!string.IsNullOrEmpty(address.County)?address.County:"--") + "</p>"
                       + "<p> State: " + address.State + "</p>"
                       + "<p> Zip: " + address.Zip + "</p>"
                       + "<h4>Thank you. Visit us again!</h4>"
                       + "<h5>Best wishes from Home Owner Bestie Team :-)</h5>",
                From    = "*****@*****.**",
                To      = user.Email,
                Subject = $"Hello {user.FirstName}! Your Home Rent Valuation Info is now ready.",
            };

            EmailConfig emailConfig = new EmailConfig()
            {
                Password = "******",
                Port     = 587,
                Smtp     = "smtp.gmail.com",
                UserName = "******"
            };

            return(Utils.SendEmail(emailEnvelope, emailConfig));
        }