Exemple #1
0
        public void ShouldReturnTheSpecifiedAddress()
        {
            string     address = "*****@*****.**";
            EmailAgent agent   = new EmailAgent(address);

            Assert.AreEqual(address, agent.Address);
        }
        /// <summary>
        /// 发送原邮箱验证码 20180523
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="emailAddress"></param>
        public async Task SendVerifyOriginalEmail(Guid accountId, string emailAddress)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            var accountByEmail = dac.GetByEmail(emailAddress);

            if (accountByEmail != null && accountByEmail.Id != accountId)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.EMAIL_BINDED, "该邮箱已绑定到其他账户");
            }

            string key  = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";
            string code = RandomAlphaNumericGenerator.GenerateAllNumber(6);

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "AccountId", accountId.ToString() },
                { "EmailAddress", emailAddress },
                { "Code", code }
            };

            RedisHelper.Set(key, dic, new TimeSpan(0, Constant.EMAIL_EXPIRED_TIME, 0));

            string subject = Resources.验证码邮箱标题;
            string content = string.Format(Resources.验证码邮箱模版, code, Constant.EMAIL_EXPIRED_TIME);

            EmailAgent agent = new EmailAgent();
            await agent.SendAsync(emailAddress, subject, content, 5);
        }
Exemple #3
0
        public void ShouldReturnTheSpecifiedName()
        {
            string     name    = "AgentName";
            string     address = "*****@*****.**";
            EmailAgent agent   = new EmailAgent(address, name);

            Assert.AreEqual(address, agent.Address);
            Assert.AreEqual(name, agent.Name);
        }
Exemple #4
0
        public void ShouldAddTheRecipientToTheRecipientsList()
        {
            EmailAgent   agent   = new EmailAgent("*****@*****.**", "mailname");
            EmailMessage message = new EmailMessage("mailmessage");

            Assert.AreEqual(0, message.Recipients.Length);
            message.AddRecipient(agent);
            Assert.AreEqual(1, message.Recipients.Length);
            Assert.AreEqual("mailname", message.Recipients[0].Name);
        }
        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);
            }
        }
Exemple #7
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);
        }
Exemple #8
0
        public void ShouldReturnEmptyStringWhenNameIsNotSpecified()
        {
            EmailAgent email_agent = new EmailAgent("*****@*****.**");

            Assert.AreEqual(string.Empty, email_agent.Name);
        }