public async Task Execute(ContactDTO customer, string key, string sender)
        {
            var         apiKey      = key;
            var         client      = new SendGridClient(apiKey);
            OtpCreation otpCreation = new OtpCreation();
            string      otp         = otpCreation.GenerateOtp();

            string FilePath = "C://Users//shilatiy//Desktop//Otpgeneration//emailNotification//NotificationService.Web//Password1.html";

            StreamReader str      = new StreamReader(FilePath);
            string       MailText = str.ReadToEnd();

            str.Close();
            MailText = MailText.Replace("[otp]", otp);



            var msg = new SendGridMessage()
            {
                From             = new EmailAddress(sender, "DX Team"),
                Subject          = "Email For verification!",
                PlainTextContent = "Forget , Password!",
                HtmlContent      = MailText
            };

            msg.AddTo(new EmailAddress(customer.Email, "Test User"));
            var response = await client.SendEmailAsync(msg);
        }
Exemple #2
0
        public void Email(ContactDTO contact)
        {
            string      emailSender         = "*****@*****.**";
            string      emailSenderPassword = "";
            string      emailSenderHost     = "smtp.apac-resources.com";
            int         emailSenderPort     = Convert.ToInt16("25");
            Boolean     emailIsSSL          = Convert.ToBoolean("false");
            OtpCreation otpCreation         = new OtpCreation();
            string      otp = otpCreation.GenerateOtp();

            string       FilePath = "C://Users//shilatiy//Desktop//Otpgeneration//emailNotification//NotificationService.Web//OTPValidation.html";
            StreamReader str      = new StreamReader(FilePath);
            string       MailText = str.ReadToEnd();

            str.Close();


            MailText = MailText.Replace("[newusername]", contact.Email.Trim());
            MailText = MailText.Replace("[otp]", otp);

            string subject = "Authentication Required";


            MailMessage _mailmsg = new MailMessage();


            _mailmsg.IsBodyHtml = true;


            _mailmsg.From = new MailAddress(emailSender);


            _mailmsg.To.Add(contact.Email.ToString());


            _mailmsg.Subject = subject;


            _mailmsg.Body = MailText;



            SmtpClient _smtp = new SmtpClient();


            _smtp.Host = emailSenderHost;


            _smtp.Port = emailSenderPort;


            _smtp.EnableSsl = emailIsSSL;


            NetworkCredential _network = new NetworkCredential(emailSender, emailSenderPassword);

            _smtp.Credentials = _network;


            try
            {
                _smtp.Send(_mailmsg);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }