public async Task SendEmail(EmailParams emailParams)
        {
            var mimeMessage = new MimeMessage();

            emailParams.ToList.ForEach(to => mimeMessage.To.Add(new MailboxAddress(to)));
            emailParams.CcList.ForEach(to => mimeMessage.Cc.Add(new MailboxAddress(to)));
            mimeMessage.From.Add(new MailboxAddress(settings.FromAddress));
            mimeMessage.Subject = emailParams.Subject;
            mimeMessage.Body    = new TextPart("plain")
            {
                Text = emailParams.Body
            };

            using var smtpClient = new SmtpClient();

            try
            {
                smtpClient.Connect(settings.Host, settings.Port, settings.Ssl);
                await smtpClient.AuthenticateAsync(settings.UserId, settings.Password);

                await smtpClient.SendAsync(mimeMessage);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Пример #2
0
        public async Task <CommandResult> Handle(PurchaseCommand purchaseCommand)
        {
            CommandResult commandResponse = ValidateCommand(purchaseCommand);

            //if (!commandResponse.Succeed)
            //{
            //    return commandResponse;
            //}
            //if (!await IsStoreServiceOn()) // REST call with auto retry policy
            //{
            //    commandResponse.Error = "Sorry! Store Service is not On. You have to wait until it is open";

            //    return commandResponse;
            //}
            if (await GetCurrentStoreItems() > 1000L) // GRPC call with Circuit breaker policy
            {
                commandResponse.Error = "Sorry! Current storeitems more than 1000. So no more purchase possible";

                return(commandResponse);
            }

            Purchase purchase = Map(purchaseCommand);
            await purchaseRepository.Save(purchase);

            ProductPurchasedEvent productPurchasedEvent = Map(purchase);
            await serviceBus.Publish(Constants.MessageQueues.PurchasedQueue, productPurchasedEvent);

            EmailParams emailParams = BuildEmailParameters(productPurchasedEvent);
            await emailService.SendEmail(emailParams);

            return(new CommandResult());
        }
Пример #3
0
        public static void Send(EmailParams eParams)
        {
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

            smtp.Credentials = new NetworkCredential("*****@*****.**", "mypassword");

            smtp.EnableSsl = true;
            smtp.Send(eParams.Message);
        }
Пример #4
0
        /// <summary>
        /// Send notification email for clients
        /// </summary>
        public async Task SendEmailAsync(EmailParams emailparams)
        {
            if (emailparams.UserList.Count == 0)
            {
                return;
            }
            foreach (var emailparam in emailparams.UserList)
            {
                var emailMessage = new MimeMessage();

                if (emailparam.UserEmail == null)
                {
                    emailparam.UserEmail = _mailParameters.SmtpRedirectEmail;
                }

                emailMessage.From.Add(new MailboxAddress("Компанія \"TEST\" ", _mailParameters.SmtpUser));

                emailMessage.Subject = emailparams.Title;

                var builder = new BodyBuilder();

                builder.HtmlBody =
                    (EmailFace.Up
                     + "<h4> Шановний(на)" + emailparam.UserFullName + "!</h4><br>"
                     + emailparams.Message
                     + EmailFace.Down);

                emailMessage.Body = builder.ToMessageBody();

                var isRedirectConfigured = !string.IsNullOrWhiteSpace(_mailParameters.SmtpRedirectEmail);
                emailMessage.To.Add(isRedirectConfigured ? new MailboxAddress("", _mailParameters.SmtpRedirectEmail) :
                                    new MailboxAddress("", emailparam.UserEmail));

                try
                {
                    using (var client = new SmtpClient())
                    {
                        client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                        await client.ConnectAsync(_mailParameters.SmtpHost, _mailParameters.SmtpPort, SecureSocketOptions.Auto);

                        await client.AuthenticateAsync(_mailParameters.SmtpUser, _mailParameters.SmtpPassword);

                        await client.SendAsync(emailMessage);

                        await client.DisconnectAsync(true);

                        client.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    var stack = (new StackTrace(ex, true)).GetFrame(0);
                    _logger.LogError($"\n\n\n Exeption in File : {stack.GetFileName()} ; \n\n\n Line : {stack.GetFileLineNumber()} ; \n\n\n Message : {ex.Message} \n\n\n");
                }
            }
        }
Пример #5
0
        private void ReceiveEmailAttachments()
        {
            Output.WriteToFile("===== IMPORT ATTACHMENTS... =====");
            EmailParams emailParams = new EmailParams(true);

            ExchangeService service = new ExchangeService();

            try
            {
                service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            }
            catch (Exception ex)
            {
                Output.WriteToFile("ERROR:" + ex.Message);
            }

            //service.AutodiscoverUrl("*****@*****.**");
            //service.AutodiscoverUrl(emailParams.EmailAddress);
            //Output.WriteToFile("a");
            //service.Url = new Uri("https://wmath.moh.gr/EWS/Exchange.asmx");
            //Output.WriteToFile("b");
            //service.Credentials = new WebCredentials("moh\\pumpinfo", "password here");
            //service.Credentials = new WebCredentials("pumpinfo", "password here", "moh");
            service.Credentials = new WebCredentials(emailParams.UserName, emailParams.Password, emailParams.Domain);
            service.AutodiscoverUrl(emailParams.EmailAddress);

            ItemView view = new ItemView(20);

            view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

            string querystring = "HasAttachments:true Kind:email IsRead:false";

            FindItemsResults <Item> results = service.FindItems(WellKnownFolderName.Inbox, querystring, view);

            foreach (EmailMessage email in results)
            {
                if (email.IsRead == false)
                {
                    //MessageBox.Show(email.Subject); //to log file...
                    email.Load();
                    foreach (var att in email.Attachments)
                    {
                        FileAttachment fileAttachment = (FileAttachment)att;

                        Output.WriteToFile("Attachment file: " + fileAttachment.Name);

                        //MessageBox.Show(fileAttachment.Name); //to log file...
                        //fileAttachment.Load("C:\\Tests\\" + fileAttachment.Name);
                        fileAttachment.Load(Application.StartupPath + "\\Import\\" + fileAttachment.Name);
                    }
                    email.IsRead = true;
                    email.Update(ConflictResolutionMode.AlwaysOverwrite);
                }
            }
            Output.WriteToFile("===== PROCEDURE COMPLETED... =====");
        }
Пример #6
0
        private void SendDBsToEachDriver()
        {
            List <Machines> machines = DbUtilities.GetSqlMachinesList().Where(i => i.Email != null && i.Email.Trim().Length > 0).ToList();

            EmailParams emailParams = new EmailParams(true);

            foreach (Machines driver in machines)
            {
                SendExportedDBsByEmail(driver.Email, emailParams);
            }
        }
Пример #7
0
        private EmailParams BuildEmailParameters(ProductPurchasedEvent @event)
        {
            long purchasedTotalPrice = 0;

            @event.LineItems.ToList().ForEach(item => purchasedTotalPrice += item.PurchaedTotalPrice);

            var emailParams = new EmailParams
            {
                Subject = "Product Purchased",
                Body    = $"The Product Purchased Amount={purchasedTotalPrice}"
            };

            emailParams.ToList.Add(Constants.EmailAddressess.AdminPurchaseEmailAddress);

            return(emailParams);
        }
Пример #8
0
        public static bool sendMessageToManager(int idUser, string message, string subject)
        {
            EmailParams emailParams = new EmailParams {
                idUser = idUser, message = message, subject = subject
            };

            try
            {
                //Post Request for Register
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:61309/api/Users/sendMessageToManager");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string emailInfo = JsonConvert.SerializeObject(emailParams, Formatting.None);

                    streamWriter.Write(emailInfo);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                //Gettting response
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                //Reading response
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    string result = streamReader.ReadToEnd();
                    //If Register succeeded
                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        return(true);
                    }
                    //Printing the matching error
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception exception)
            {
                return(false);
            }
        }
Пример #9
0
 public HttpResponseMessage sendMessageToManager([FromBody] EmailParams emailParams)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, LogicManager.sendEmailToManager(emailParams.idUser, emailParams.message, emailParams.subject)));
 }
Пример #10
0
        /*private void SendExportedDBsByEmail_ori(string MailTo, EmailParams emailParams)
         * {
         *  Output.WriteToFile("===== SENDING MAIL... =====");
         *  Output.WriteToFile("To: " + MailTo);
         *
         *  string targetDirectory = Application.StartupPath.Replace("PumpAnalysis", "PumpData") + "\\ExportedDBs\\";
         *
         *
         *  string Archived_db_file = targetDirectory + "Archived.db"; //@"C:\Repos\PumpInfo\PumpData\bin\Debug\ExportedDBs\Archived.db";
         *  string StationGeoData_db_file = targetDirectory + "StationGeoData.db"; //@"C:\Repos\PumpInfo\PumpData\bin\Debug\ExportedDBs\StationGeoData.db";
         *
         *  //System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("*****@*****.**", MailTo, "Συγχρονισμός Βάσεων - DBs Synchronization",
         *  System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(emailParams.EmailAddress, MailTo, "Συγχρονισμός Βάσεων - DBs Synchronization",
         *      "Χρησιμοποιείστε τα συνημμένα αρχεία για να συγχρονίσετε τη βάση σας. \r\n" +
         *      "Πατήστε το κουμπί 'Sync', επιλέξτε 'Πρατήρια' επιλέγοντας το αρχείο 'StationGeoData.db' και 'Επισκέψεις' επιλέγοντας το αρχείο 'Archived.db' \r\n\r\n" +
         *      "Use attachments to synchronize your database. \r\n" +
         *      "Click the button 'Sync', then button 'Pratiria' and select file 'StationGeoData.db' and click the button 'Episkepseis' and select the file 'Archived.db' ");
         *  //System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
         *  //message.Attachments.Add(data);
         *  try
         *  {
         *      System.Net.Mail.Attachment att_Archived_db = new System.Net.Mail.Attachment(Archived_db_file, System.Net.Mime.MediaTypeNames.Application.Octet);
         *      System.Net.Mail.Attachment att_StationGeoData_db = new System.Net.Mail.Attachment(StationGeoData_db_file, System.Net.Mime.MediaTypeNames.Application.Octet);
         *      message.Attachments.Add(att_Archived_db);
         *      message.Attachments.Add(att_StationGeoData_db);
         *  }
         *  catch (Exception exAtt)
         *  {
         *      Output.WriteToFile("Exception occured: " + exAtt.Message + " \r\n " + exAtt.ToString());
         *      return;
         *  }
         *
         *  System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
         *
         *  client.Host = emailParams.SmtpClientHost; //"wmath.moh.gr";
         *  //client.Credentials = new System.Net.NetworkCredential("pumpinfo", "password here");
         *  client.Credentials = new System.Net.NetworkCredential(emailParams.UserName, emailParams.Password, emailParams.Domain);
         *
         *  client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
         *
         *  try
         *  {
         *      client.Send(message);
         *  }
         *  catch (Exception ex)
         *  {
         *      //MessageBox.Show("Exception occured: " + ex.Message + " \r\n {0}", ex.ToString());
         *      Output.WriteToFile("Exception occured: " + ex.Message + " \r\n " + ex.ToString());
         *  }
         *
         *  Output.WriteToFile("===== MAIL SENT... =====");
         *
         * }
         */

        private void SendExportedDBsByEmail(string MailTo, EmailParams emailParams)
        {
            Output.WriteToFile("===== SENDING MAIL... =====");
            Output.WriteToFile("To: " + MailTo);

            ExchangeService service = new ExchangeService();

            try
            {
                service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            }
            catch (Exception ex)
            {
                Output.WriteToFile("ERROR:" + ex.Message);
            }


            service.Credentials = new WebCredentials(emailParams.UserName, emailParams.Password, emailParams.Domain);
            service.AutodiscoverUrl(emailParams.EmailAddress);

            string targetDirectory = Application.StartupPath.Replace("PumpAnalysis", "PumpData") + "\\ExportedDBs\\";


            string Archived_db_file       = targetDirectory + "Archived.db";       //@"C:\Repos\PumpInfo\PumpData\bin\Debug\ExportedDBs\Archived.db";
            string StationGeoData_db_file = targetDirectory + "StationGeoData.db"; //@"C:\Repos\PumpInfo\PumpData\bin\Debug\ExportedDBs\StationGeoData.db";

            String subject = "Συγχρονισμός Βάσεων - DBs Synchronization";
            String body    = "Χρησιμοποιείστε τα συνημμένα αρχεία για να συγχρονίσετε τη βάση σας. \r\n" +
                             "Πατήστε το κουμπί 'Sync', επιλέξτε 'Πρατήρια' επιλέγοντας το αρχείο 'StationGeoData.db' και 'Επισκέψεις' επιλέγοντας το αρχείο 'Archived.db' \r\n\r\n" +
                             "Use attachments to synchronize your database. \r\n" +
                             "Click the button 'Sync', then button 'Pratiria' and select file 'StationGeoData.db' and click the button 'Episkepseis' and select the file 'Archived.db' ";

            EmailMessage email = new EmailMessage(service);

            email.Subject = subject;
            email.Body    = new MessageBody(BodyType.Text, body);
            email.ToRecipients.Add(MailTo);

            try
            {
                email.Attachments.AddFileAttachment(Archived_db_file);
                email.Attachments.AddFileAttachment(StationGeoData_db_file);
            }
            catch (Exception exAtt)
            {
                Output.WriteToFile("Exception occured: " + exAtt.Message + " \r\n " + exAtt.ToString());
                return;
            }

            try
            {
                email.Send();
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Exception occured: " + ex.Message + " \r\n {0}", ex.ToString());
                Output.WriteToFile("Exception occured: " + ex.Message + " \r\n " + ex.ToString());
            }

            Output.WriteToFile("===== MAIL SENT... =====");
        }