Ejemplo n.º 1
0
 public ActionResult Create(SendEmailDto email)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string result = SendEmailDao.Instance.SaveEmail(email, "add");
             if (result != "OK")
             {
                 ViewBag.Message = result;
                 ModelState.Clear();
             }
             else
             {
                 //ViewBag.Status = TempData["Dropdown"];
                 ViewBag.Message = "Successfully !!";
                 //KRPBL.Component.Common.Form.SetAlertMessage(this,"ไม่พบ User ID ที่ระบุ กรุณาตรวจสอบ");
                 ModelState.Clear();
             }
         }
         return(View());
     }
     catch (Exception e)
     {
         ViewBag.Message = "Error : " + e.Message;
         return(View());
     }
 }
Ejemplo n.º 2
0
        public string SaveEmail(SendEmailDto model, string action)
        {
            string result = "OK";

            try
            {
                conn = CreateConnection();
                MySqlCommand cmd = new MySqlCommand("PD002_SAVE_EMAIL", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                MySqlParameterCollection param = cmd.Parameters;
                param.Clear();
                AddSQLParam(param, "@id", Util.NVLInt(model.id));
                AddSQLParam(param, "@name", Util.NVLString(model.name));
                AddSQLParam(param, "@active", Util.NVLInt(model.active));
                AddSQLParam(param, "@status", action);

                conn.Open();
                MySqlDataReader read = cmd.ExecuteReader();
                while (read.Read())
                {
                    result = read.GetString(0).ToString();
                }
                conn.Close();
            }
            catch (Exception e)
            {
                result = e.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public Task <bool> SendEmail(SendEmailDto mailInfo)
        {
            HaveBeenCalled = true;
            bool ReturnTrue() => true;

            return(new Task <bool>(ReturnTrue));
        }
Ejemplo n.º 4
0
        public void Send(SendEmailDto dto)
        {
            var user = _context.Users.Find(dto.UserId);


            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential("*****@*****.**", "milosmilos12345")
            };

            var message = new MailMessage("*****@*****.**", user.Email);

            message.Subject    = dto.Subject;
            message.Body       = dto.Content;
            message.IsBodyHtml = true;
            if (_actor.Id == 1)
            {
                smtp.Send(message);
            }
        }
Ejemplo n.º 5
0
        private static bool DoSend(SendEmailDto sendEmailDto)
        {
            try
            {
                var message = new MailMessage
                {
                    IsBodyHtml = true,
                    From       = new MailAddress(sendEmailDto.FromAddress.EmailAddress, sendEmailDto.FromAddress.DisplayName),
                    Subject    = sendEmailDto.Subject,
                    Body       = sendEmailDto.MessageBody
                };

                using (var smtpClient = new SmtpClient(sendEmailDto.Host, sendEmailDto.Port))
                {
                    message.To.Add(new MailAddress(sendEmailDto.ToAddress.EmailAddress, sendEmailDto.ToAddress.DisplayName));
                    smtpClient.Send(message);
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(false);
            }
        }
Ejemplo n.º 6
0
        public void Execute(ApplicationUser request)
        {
            request.CreatedAt = DateTime.Now;

            HashSalt hashSalt = Password.GenerateSaltedHash(64, request.Password);

            request.Password = hashSalt.Hash;
            request.Salt     = hashSalt.Salt;

            //Since user is registering for the first time on the app, his default role will be Developer
            request.RoleId = context.Roles.FirstOrDefault(x => x.Name == "Developer").Id;
            context.Add(request);
            context.SaveChanges();


            //Send email
            SendEmailDto sendEmailDto = new SendEmailDto
            {
                SendTo  = request.Email,
                Subject = "Successfull registration to Bug Tracker",
                Content = "Welcome to Bug Tracker"
            };

            _emailSender.SendEmail(sendEmailDto);
        }
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Iniciando exemplo");
                Console.WriteLine("************************************");

                Dictionary <string, string> payload = new Dictionary <string, string>();
                payload.Add("Text", "Teste 1");
                payload.Add("TesteDoido", "Validação");

                SendEmailDto dto = new SendEmailDto(sender: "*****@*****.**",
                                                    destination: "*****@*****.**",
                                                    subject: "Teste1",
                                                    payload: payload,
                                                    idTemplate: "601b023a092ae3eafea1234b",
                                                    user: "******");

                var validate = _proxy.SendEmailFromTemplate(dto).Result;

                Console.WriteLine(validate ? "Email enviado com sucesso!" : "Email não enviado");
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Console.WriteLine("************************************");
                Console.ReadLine();
            }
        }
        public ActionResult TrueSendEmail(SendEmailDto sendEmailDto)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Саттаров Марсэль", "*****@*****.**"));

            message.To.Add(new MailboxAddress(sendEmailDto.Email, sendEmailDto.Email));

            message.Subject = sendEmailDto.Subject;

            message.Body = new TextPart("plain")
            {
                Text = sendEmailDto.Message
            };

            // configure and send email
            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587);

                // Note: since we don't have an OAuth2 token, disable
                // the XOAUTH2 authentication mechanism.
                client.AuthenticationMechanisms.Remove("XOAUTH2");

                // Note: only needed if the SMTP server requires authentication
                client.Authenticate("*****@*****.**", "pubgthebest");

                client.Send(message);
                client.Disconnect(true);
            }

            return(RedirectToRoute(new { controller = "AuthorizedAccount", action = "Employee" }));
        }
        private void SendEmail(SendEmailDto dto)
        {
            EmailConfigurationEntity configuration = this._emailConfigurationRepository.Get(x => x.UserName.Equals(dto.User)).Result.FirstOrDefault();

            MailMessage mailMessage = new MailMessage(from: dto.Sender, to: dto.To, subject: dto.Subject, body: dto.Html)
            {
                IsBodyHtml = true
            };

            foreach (string item in dto.CCDestinations)
            {
                mailMessage.CC.Add(item);
            }

            foreach (string item in dto.BCCDestinations)
            {
                mailMessage.Bcc.Add(item);
            }

            SmtpClient client = new SmtpClient(host: configuration.Host, port: configuration.Port)
            {
                EnableSsl = true,
            };

            client.UseDefaultCredentials = false;

            client.Credentials = new NetworkCredential(userName: configuration.UserName, password: configuration.Password);

            client.Send(mailMessage);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Envoi un email smtp
        /// </summary>
        /// <param name="sendEmail">SendEmailDto</param>
        /// <returns>true si le mail à bien été envoyé</returns>
        public bool SendEmail(SendEmailDto sendEmail)
        {
            MailMessage message = new MailMessage(ADRESSE_EMAIL_EXPEDITEUR, sendEmail.Email);

            message.Subject = sendEmail.Subject;
            message.Body    = sendEmail.Message;

            using (SmtpClient smtp = new SmtpClient())
            {
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.EnableSsl             = true;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.Credentials = new System.Net.NetworkCredential(ADRESSE_EMAIL_EXPEDITEUR, "projetFilRouge");
                // send the email
                try
                {
                    smtp.Send(message);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
        public async Task WhenMessageIsTemplatedThenSubjectIsFormatted()
        {
            var source = new Mock <IEmailSender>();

            SendEmailDto saveDto = null;

            source.Setup(c => c.SendAsync(It.IsAny <SendEmailDto>()))
            .Callback <SendEmailDto>((dto) => saveDto = dto)
            .Returns(Task.CompletedTask);

            var emailService = new EmailNotificationService(source.Object);
            var message      = new TemplatedTestEmailNotification(
                "*****@*****.**",
                "Softeq Unit Test",
                new TestEmailModel("google.com", "Softeq Unit Test"));

            await emailService.SendAsync(message);

            var expectedSubject = string.Format(message.Subject, message.TemplateModel.Name);

            source.Verify(sender => sender.SendAsync(It.IsAny <SendEmailDto>()), Times.Once);
            Assert.NotNull(saveDto);
            Assert.Equal(message.Text, saveDto.Text);
            Assert.Equal(message.Recipients, saveDto.Recipients);
            Assert.Equal(expectedSubject, saveDto.Subject);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Send mails using SendGrid API
        /// </summary>
        /// <param name="mailInfo">datas to send</param>
        /// <returns>true if all mails are accepted by sendgrid, otherwise false</returns>
        public async Task <bool> SendEmail(SendEmailDto mailInfo)
        {
            var apiKey = SendGridApiKey;
            var client = new SendGridClient(apiKey);

            foreach (var t in mailInfo.Receviers)
            {
                var from    = new EmailAddress(mailInfo.Sender.Key, mailInfo.Sender.Value);
                var subject = mailInfo.Subject;
                var to      = new EmailAddress(t.Key, t.Value);
                var text    = mailInfo.Body;

                SendGridMessage msg;
                if (mailInfo.IsHtml)
                {
                    msg = MailHelper.CreateSingleEmail(from, to, subject, string.Empty, text);
                }
                else
                {
                    msg = MailHelper.CreateSingleEmail(from, to, subject, text, string.Empty);
                }

                var response = await client.SendEmailAsync(msg);

                if (response.StatusCode != System.Net.HttpStatusCode.Accepted)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 13
0
        public async Task <bool> SendAsync(SendEmailDto sendEmailDto, bool isHtml)
        {
            // ReSharper disable StringLiteralTypo
            var mailClient = new SmtpClient(ConfigurationManager.AppSettings["AWSSMTPHost"], Convert.ToInt32(ConfigurationManager.AppSettings["AWSSMTPPort"]))
            {
                Credentials =
                    new NetworkCredential(ConfigurationManager.AppSettings["AWSSMTPUser"],
                                          ConfigurationManager.AppSettings["AWSSMTPPass"]),
                EnableSsl = true
            };

            // ReSharper restore StringLiteralTypo


            mailClient.EnableSsl = false;

            var message = new MailMessage(sendEmailDto.From, sendEmailDto.To)
            {
                Subject    = sendEmailDto.Subject,
                Body       = sendEmailDto.Body,
                IsBodyHtml = isHtml
            };

            if (sendEmailDto.Attachments.Count > 0)
            {
                foreach (var attach in sendEmailDto.Attachments)
                {
                    message.Attachments.Add(attach);
                }
            }
            await mailClient.SendMailAsync(message);

            return(true);
        }
Ejemplo n.º 14
0
 public bool SendEmail(SendEmailDto item)
 {
     try
     {
         SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
         var        mail       = new MailMessage();
         mail.To.Add(item.ToEmail);
         mail.From       = new MailAddress(item.Email);
         mail.Subject    = item.Subject + " - " + item.UserName + " - " + item.Phone + " - " + item.Email;
         mail.IsBodyHtml = true;
         string htmlBody;
         htmlBody        = item.Message;
         mail.Body       = htmlBody;
         SmtpServer.Port = 587;
         SmtpServer.UseDefaultCredentials = false;
         SmtpServer.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "Albasti@123");
         SmtpServer.EnableSsl             = true;
         SmtpServer.Send(mail);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 15
0
        public Task <bool> SendEmail(SendEmailDto mailInfo)
        {
            var handler = SendMailCalled;

            handler?.Invoke(this, mailInfo);

            return(Task <bool> .Factory.StartNew(() => { return true; }));
        }
Ejemplo n.º 16
0
        public async Task SendEmail(SendEmailDto sendEmail)
        {
            var         Email   = _emailSettings.Email;
            MimeMessage message = PrepareMsg(sendEmail);

            message.From.Add(new MailboxAddress(Email));
            await PrepareClient(message);
        }
Ejemplo n.º 17
0
        public static bool Process(EmailQueueDto emailQueue)
        {
            var readySubject = ReplaceReplacements(emailQueue.SubjectTemplate, emailQueue.Replacements);
            var readyBody    = ReplaceReplacements(emailQueue.BodyTemplate, emailQueue.Replacements);
            var sendEmailDto = new SendEmailDto(emailQueue.EmailQueueId, emailQueue.From, emailQueue.To, readyBody, readySubject, emailQueue.Host, emailQueue.Port);

            return(EmailHelper.SendEmail(sendEmailDto));
        }
Ejemplo n.º 18
0
        public async Task Post_Should_Create_User()
        {
            var userName          = "******";
            var password          = "******";
            var encryptionService = new EncryptionService();
            var hashPassword      = encryptionService.Sha256Hash($"{GuiApiTestStartup.Configuration.PasswordSalt}{password}");

            SendEmailDto mailSentInfos = null;

            _fakeMailService.SendMailCalled += delegate(object sender, SendEmailDto e)
            {
                mailSentInfos = e;
            };

            var createUserDto = new CreateUserDto()
            {
                BirthDate      = DateTime.Now.AddYears(-41),
                EMail          = "*****@*****.**",
                FullName       = "johnny lecrabe",
                Password       = password,
                RepeatPassword = password,
                UserName       = userName
            };

            var httpResponseMessage = await _client.PostAsJsonAsync("users", createUserDto);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseMessage.StatusCode);

            Assert.IsNotNull(mailSentInfos);
            Assert.IsNotNull(mailSentInfos.Receviers.FirstOrDefault());
            Assert.AreEqual(createUserDto.EMail, mailSentInfos.Receviers.First().Key);

            User userFromDb = null;

            using (var context = new DaOAuthContext(_dbContextOptions))
            {
                userFromDb = context.Users.FirstOrDefault(u => u.UserName.Equals(userName));
            }

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(createUserDto.BirthDate, userFromDb.BirthDate);
            Assert.AreEqual(createUserDto.EMail, userFromDb.EMail);
            Assert.AreEqual(DateTime.Now.Date, userFromDb.CreationDate.Date);
            Assert.AreEqual(createUserDto.FullName, userFromDb.FullName);
            Assert.IsTrue(hashPassword.SequenceEqual <byte>(userFromDb.Password));
            Assert.IsFalse(userFromDb.IsValid);

            IList <UserRole> userRolesFromDb = null;

            using (var context = new DaOAuthContext(_dbContextOptions))
            {
                userRolesFromDb = context.UsersRoles.Where(ur => ur.UserId.Equals(userFromDb.Id)).ToList();
            }
            Assert.IsNotNull(userRolesFromDb);
            Assert.IsTrue(userRolesFromDb.Count() > 0);
            Assert.IsNotNull(userRolesFromDb.FirstOrDefault(ur => ur.Id.Equals((int)ERole.USER)));
            Assert.IsNull(userRolesFromDb.FirstOrDefault(ur => ur.Id.Equals((int)ERole.ADMIN)));
        }
Ejemplo n.º 19
0
        public static bool SendEmail(SendEmailDto sendEmailDto)
        {
            var debugSendingEmailsOn = ConfigurationHelper.GetBoolean(ConfigurationNames.DebugSendingEmailsOn, ConfiguratoinDefaultValues.DebugSendingEmailsOn);

            if (debugSendingEmailsOn)
            {
                Console.WriteLine($"Email was sent id: {sendEmailDto.Id}");
                return(true);
            }
            return(DoSend(sendEmailDto));
        }
Ejemplo n.º 20
0
        private MimeMessage PrepareMsg(SendEmailDto sendEmail)
        {
            MimeMessage message = new MimeMessage();

            message.To.Add(new MailboxAddress(sendEmail.To));
            message.Subject = sendEmail.Subject;

            message.Body = new TextPart("plain")
            {
                Text = sendEmail.Body
            };
            return(message);
        }
Ejemplo n.º 21
0
        public async Task Should_Use_SendGrid_ToSendEmail()
        {
            // Arrange
            var sendEmailInfo = new SendEmailDto
            {
                Email    = "*****@*****.**",
                Body     = "Hello there",
                Subject  = "Test Email",
                FromName = "My Company",
                ToName   = "Test User"
            };

            var options = Options.Create(new SendGridSettings()
            {
                Key       = "testKey",
                FromEmail = "*****@*****.**",
                FromName  = "Mike"
            });

            var client  = new SendGridClient(options.Value.Key);
            var message = new SendGridMessage();
            var from    = new EmailAddress(options.Value.FromEmail, options.Value.FromName);
            var to      = new EmailAddress(sendEmailInfo.Email, sendEmailInfo.ToName);

            var mockHttpContent = new Mock <HttpContent>();
            var response        = new Response(HttpStatusCode.OK, mockHttpContent.Object, null);

            var mockSendGridService = new Mock <ISendGridClientService>();

            mockSendGridService.Setup(m => m.CreateToAddress(sendEmailInfo.Email, sendEmailInfo.ToName))
            .Returns(to);

            mockSendGridService.Setup(m => m.CreateFromAddress())
            .Returns(from);

            mockSendGridService.Setup(m => m.Create()).Returns(client);

            mockSendGridService.Setup(m =>
                                      m.CreateSingleEmail(from, to, sendEmailInfo.Subject, sendEmailInfo.Body, sendEmailInfo.Body)).Returns(message);

            mockSendGridService.Setup(m => m.SendEmailAsync(message, client)).Returns(Task.FromResult(response));

            var sut = new SendEmailService(mockSendGridService.Object);

            // Act
            await sut.SendAsync(sendEmailInfo.Email, sendEmailInfo.Subject, sendEmailInfo.Body, sendEmailInfo.ToName);

            // Assert
            mockSendGridService.Verify(m => m.SendEmailAsync(message, client), Times.Once);
        }
Ejemplo n.º 22
0
        public async Task SendRegistrationEmailAsync(RegistrationEmailDto model)
        {
            var sendEmail = new SendEmailDto()
            {
                EmailAddress = model.EmailAddress,
                Data         = new List <SendEmailDto.DataItem>()
                {
                    new SendEmailDto.DataItem {
                        Value = model.CallBackUrl, Key = "ActivationUrl"
                    },
                },
                Name = model.EmailName
            };

            await _caseflowApiProxy.SendRegistrationEmailAsync(sendEmail, model.LowellReference, model.ReplayId);
        }
Ejemplo n.º 23
0
 // GET: MemberList/Delete/5
 public ActionResult Delete(SendEmailDto model)
 {
     try
     {
         string result = SendEmailDao.Instance.SaveEmail(model, "del");
         if (result == "OK")
         {
             ViewBag.Message = "Student Deleted Successfully";
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         ViewBag.Message = "Error : " + e.Message.ToString();
         return(View());
     }
 }
Ejemplo n.º 24
0
        public void SendContactUsEmail(ContactUsModel model)
        {
            var dto = new SendEmailDto
            {
                SenderName     = model.SenderName,
                PhoneNumber    = model.PhoneNumber,
                IdTour         = model.IdTour,
                Costs          = model.Costs,
                Start          = model.Start,
                Resort         = model.Resort,
                PeopleCount    = model.PeopleCount,
                FoodSupplyType = model.FoodSupplyType,
                NameHotel      = model.NameHotel
            };

            _emailService.SendEmail(dto, CONTACT_US_SUBJECT);
        }
Ejemplo n.º 25
0
        public async Task Get_New_Password_Should_Send_Mail()
        {
            SendEmailDto mailSentInfos = null;

            _fakeMailService.SendMailCalled += delegate(object sender, SendEmailDto e)
            {
                mailSentInfos = e;
            };

            var httpResponseMessage = await _client.GetAsync($"users/password/{_sammyUser.EMail}");

            Assert.IsTrue(httpResponseMessage.IsSuccessStatusCode);

            Assert.IsNotNull(mailSentInfos);
            Assert.IsNotNull(mailSentInfos.Receviers.FirstOrDefault());
            Assert.AreEqual(_sammyUser.EMail, mailSentInfos.Receviers.First().Key);
        }
        public void Send(SendEmailDto dto)
        {
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential("*****@*****.**", "AspJeNajjaciPredmet")
            };
            var message = new MailMessage("*****@*****.**", dto.SendTo);

            message.Subject    = dto.Subject;
            message.Body       = dto.Content;
            message.IsBodyHtml = true;
            smtp.Send(message);
        }
        public void Send(SendEmailDto dto)
        {
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential("*****@*****.**", "Sifra123!")
            };
            var message = new MailMessage("*****@*****.**", dto.SendTo);

            message.Subject    = dto.Subject;
            message.Body       = dto.Content;
            message.IsBodyHtml = true;
            smtp.Send(message);
        }
Ejemplo n.º 28
0
        public void Send(SendEmailDto dto)
        {
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential("*****@*****.**", "dalijeovokristinamarkovic988")
            };

            var message = new MailMessage("*****@*****.**", dto.SendTo);

            message.Subject    = dto.Subject;
            message.Body       = dto.Content;
            message.IsBodyHtml = true;
            smtp.Send(message);
        }
Ejemplo n.º 29
0
        public void Send(SendEmailDto emailDto)
        {
            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential("*****@*****.**", "theend27198")
            };

            var message = new MailMessage("*****@*****.**", emailDto.SendTo);

            message.Subject    = emailDto.Subject;
            message.Body       = emailDto.Content;
            message.IsBodyHtml = true;
            smtp.Send(message);
        }
Ejemplo n.º 30
0
        public void SendEmail(SendEmailDto dto)
        {
            var smtp = new SmtpClient
            {
                Host                  = mailSettings.Host,
                Port                  = mailSettings.Port,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(mailSettings.Mail, mailSettings.Password)
            };

            var message = new MailMessage(mailSettings.Mail, dto.SendTo);

            message.Subject    = dto.Subject;
            message.Body       = dto.Content;
            message.IsBodyHtml = true;
            smtp.Send(message);
        }