private void SendUpdateEmail(int accountId, int neverBounceRequestId, int userId)
        {
            if (neverBounceRequestId != 0 & accountId != 0)
            {
                Guid    loginToken          = new Guid();
                string  accountPrimaryEmail = string.Empty;
                Email   senderEmail         = new Email();
                Account account             = accountService.GetAccountMinDetails(accountId);
                string  toEmail             = ConfigurationManager.AppSettings["NeverBounce_Update_Email"];
                if (account != null && !string.IsNullOrEmpty(toEmail))
                {
                    if (account.Email != null)
                    {
                        accountPrimaryEmail = account.Email.EmailId;
                    }

                    IEnumerable <ServiceProvider> serviceProviders = serviceProviderRepository.GetAccountCommunicationProviders(accountId, CommunicationType.Mail, MailType.TransactionalEmail);
                    if (serviceProviders != null && serviceProviders.FirstOrDefault() != null)
                    {
                        loginToken  = serviceProviders.FirstOrDefault().LoginToken;
                        senderEmail = serviceProviderRepository.GetServiceProviderEmail(serviceProviders.FirstOrDefault().Id);
                    }

                    var tomails = toEmail.Split(',');
                    foreach (string ToMail in tomails)
                    {
                        if (loginToken != new Guid() && accountPrimaryEmail != null)
                        {
                            string fromEmail = (senderEmail != null && !string.IsNullOrEmpty(senderEmail.EmailId)) ? senderEmail.EmailId : accountPrimaryEmail;

                            EmailAgent      agent       = new EmailAgent();
                            SendMailRequest mailRequest = new SendMailRequest();
                            mailRequest.Body          = GetBody(neverBounceRequestId, accountId, userId);
                            mailRequest.From          = fromEmail;
                            mailRequest.IsBodyHtml    = true;
                            mailRequest.ScheduledTime = DateTime.Now.ToUniversalTime().AddSeconds(5);
                            mailRequest.Subject       = string.Format("{0} - Email List Finished Validating", account.AccountName);
                            mailRequest.To            = new List <string>()
                            {
                                ToMail
                            };
                            mailRequest.TokenGuid     = loginToken;
                            mailRequest.RequestGuid   = Guid.NewGuid();
                            mailRequest.AccountDomain = account.DomainURL;
                            mailRequest.CategoryID    = (byte)EmailNotificationsCategory.MailTesterEmail;
                            mailRequest.AccountID     = accountId;
                            agent.SendEmail(mailRequest);
                        }
                    }
                }
            }
        }
        public void SendEmail(string bodyMessage, string subject)
        {
            try
            {
                ServiceProvider ServiceProviders = serviceProviderRepository
                                                   .GetServiceProviders(1, CommunicationType.Mail, MailType.TransactionalEmail);

                LandmarkIT.Enterprise.CommunicationManager.Requests.SendMailRequest sendMailRequest = new LandmarkIT.Enterprise.CommunicationManager.Requests.SendMailRequest();

                Logger.Current.Verbose("Account Id in LeadAdapter:" + leadAdapterAndAccountMap.AccountID);
                Logger.Current.Verbose("Email Guid in LeadAdapter :" + ServiceProviders.LoginToken);

                string _supportEmailId = ConfigurationManager.AppSettings["SupportEmailId"];
                string machine         = ConfigurationManager.AppSettings["MachineName"];
                string subjct          = leadAdapterAndAccountMap.AccountName + " - " + subject;
                if (machine != "" && machine != null)
                {
                    subjct = machine + " : " + subjct;
                }

                var body = " Error Message     : " + subject + ".\r\n Account Name     : " + leadAdapterAndAccountMap.AccountName + ".\r\n LeadAdapter        :  " + leadAdapterAndAccountMap.LeadAdapterTypeID.ToString() + "  .\r\n Instance occured on  : " + DateTime.UtcNow + " (UTC).\r\n More Info            : " + bodyMessage;

                Logger.Current.Verbose("Sending Email in LeadAdapter Engine :" + _supportEmailId);
                _supportEmailId = _supportEmailId == null ? "*****@*****.**" : _supportEmailId;
                List <string> To = new List <string>();
                To.Add(_supportEmailId);
                EmailAgent agent = new EmailAgent();
                sendMailRequest.TokenGuid   = ServiceProviders.LoginToken;
                sendMailRequest.From        = _supportEmailId;
                sendMailRequest.IsBodyHtml  = true;
                sendMailRequest.DisplayName = "";
                sendMailRequest.To          = To;
                sendMailRequest.Subject     = subjct;
                sendMailRequest.Body        = body;
                sendMailRequest.RequestGuid = Guid.NewGuid();
                var varsendMailresponse = agent.SendEmail(sendMailRequest);
                if (varsendMailresponse.StatusID == LandmarkIT.Enterprise.CommunicationManager.Responses.CommunicationStatus.Success)
                {
                    Logger.Current.Informational("Support mail sent successfully");
                }
                Logger.Current.Verbose("Sending Email in LeadAdapter Engine :" + _supportEmailId);
            }
            catch (Exception ex)
            {
                Logger.Current.Error("An exception occured while sending email: ", ex);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                BootstrapConfiguration();
                var ip           = Configuration.GetSection(SMTP_IpAddress).Value;
                var port         = Configuration.GetSection(SMTP_PortNumber).Value;
                var useSsl       = Configuration.GetSection(SMTP_SSL).Value;
                var userName     = Configuration.GetSection(SMTP_UserName).Value;
                var userPassword = Configuration.GetSection(SMTP_UserPassword).Value;

                Console.WriteLine($"The value of ip is {ip}");
                Console.WriteLine($"The value of port is {port}");
                Console.WriteLine($"The value of SSL is {useSsl}");
                Console.WriteLine($"The value of username is {userName}");
                Console.WriteLine($"The value of userPassword is {userPassword}");

                IEmailAgent emailAgent = new EmailAgent
                {
                    SMTP_IP       = ip.ToString(),
                    SMTP_Port     = int.Parse(port),
                    SMTP_Ssl      = bool.Parse(useSsl),
                    SMTP_User     = userName,
                    SMTP_Password = userPassword
                };

                string[] attachments = new string[] { @"C:\Users\ka8kgj\Desktop\freeze.txt" };
                string   fromEmail   = "*****@*****.**";
                string   fromName    = "jstevens";
                string   toEmail     = "*****@*****.**";
                string   subjectLine = "This is a test Email";
                string   emailBody   = "<h1>Testing</h1><strong>This is a test</strong>";

                emailAgent.SendEmail(fromEmail, fromName, toEmail, subjectLine, emailBody, true, attachments);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("Test complete. Hit any key to end.");
            Console.ReadKey(true);
        }