Example #1
0
        private void SendAuthorizationEmail(User newUser)
        {
            // Set up the message
            string messageBody = MessageBodyTop;

            string messageAuth =
                MessageBodyAuthCode.Replace(AuthCodeText, newUser.VerificationCode.ToString());

            messageBody += messageAuth;

            string messageTime =
                MessageBodyActivateTime.Replace(ActivateTimeText, newUser.VerificationByTime.ToString("HH:mm:ss tt"));

            messageBody += messageTime;

            messageBody += MessageBodyBottom;

            // Set up the mail connection parameters
            StmpConnection connection =
                new StmpConnection(_smtpConfig.EmailAddress, _smtpConfig.Password);

            // Set up the message parameters
            HtmlEmailDefinition emailDefinition =
                new HtmlEmailDefinition
            {
                FromEmailDisplayName = _smtpConfig.Username,
                ToEmail            = newUser.Email,
                ToEmailDisplayName = newUser.Name,
                Subject            = MessageSubject,
                BodyHtml           = messageBody
            };

            SmtpEmailer.SendHtmlEmail(connection, emailDefinition);
        }
Example #2
0
        private void SendExportEmailToUser(ExportDataToEmailRequest exportRequest)
        {
            // Set up the message
            string messageBody = MessageBodyTop;

            string messageAuth =
                MessageBodyAuthCode.Replace(AuthCodeText, "some code");

            messageBody += messageAuth;

            string messageTime =
                MessageBodyActivateTime.Replace(ActivateTimeText, "xsome time");

            messageBody += messageTime;

            messageBody += MessageBodyBottom;

            // Set up the mail connection parameters
            StmpConnection connection =
                new StmpConnection(_smtpConfig.EmailAddress, _smtpConfig.Password);

            // Set up the message parameters
            HtmlEmailDefinition emailDefinition =
                new HtmlEmailDefinition
            {
                FromEmailDisplayName = _smtpConfig.Username,
                ToEmail            = exportRequest.DestinationEmail,
                ToEmailDisplayName = "Guy we know",
                Subject            = MessageSubject,
                BodyHtml           = messageBody
            };

            SmtpEmailer.SendHtmlEmail(connection, emailDefinition);
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Address.Text = Request.Params["mail"];

            try
            {
                SmtpEmailer eml = new SmtpEmailer();
                eml.Dns  = ConfigSettings.DNS1;
                eml.Dns  = ConfigSettings.DNS2;
                eml.From = "*****@*****.**";
                string Result = eml.CheckMail((Address.Text.Length > 0)?Address.Text.Split(';')[0]:"");
                eml = null;
                switch (Result.Substring(0, 2))
                {
                case "OK":
                    Address.Text += "<p><img src=\"/i/thumbup.gif\"></p>";
                    break;

                case "KO":
                    Address.Text += "<p><img src=\"/i/thumbdown.gif\"></p>";
                    break;

                case "??":
                    Address.Text += "<p><img src=\"/i/thumbni.gif\"></p>";
                    break;
                }
                Address.ToolTip = Result;
            }
            catch
            {
                Address.Text    = Address.Text;
                Address.Text   += "<p><img src=\"/i/thumbni.gif\"></p>";
                Address.ToolTip = "Inpossible to verify, connection denied";
            }
        }
Example #4
0
        public async Task CanSendEmailWithoutAttachments()
        {
            var mailer = new SmtpEmailer(new MockedSmtpConfiguration(), new MockedEmailConfiguration());

            await mailer.Send(
                "*****@*****.**",
                "Unit Test (no attachments)",
                "This is the <b>HTML</b> body.",
                "This is the **Text** body.");
        }
Example #5
0
        public async Task CanSendEmailWithAttachments()
        {
            var mailer = new SmtpEmailer(new MockedSmtpConfiguration(), new MockedEmailConfiguration());

            await mailer.Send(
                "*****@*****.**",
                "Unit Test (with attachments)",
                "This is the <b>HTML</b> body.<br /><br />And <a href='https://www.igevia.com'>this</a> is a link.",
                "This is the **Text** body.",
                new MockedEmailAttachment("textfile.txt", new byte[] { 1 }),
                new MockedEmailAttachment("musicfile.mp3", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        }
Example #6
0
        public async Task CannotSendEmailWithoutAuthentication()
        {
            var smtpConfig = new MockedSmtpConfiguration {
                UserName = ""
            };
            var mailer = new SmtpEmailer(smtpConfig, new MockedEmailConfiguration());

            await Assert.ThrowsAsync <Exception>(async() =>
            {
                await mailer.Send(
                    "*****@*****.**",
                    "Unit Test (no attachments)",
                    "This is the <b>HTML</b> body.",
                    "This is the **Text** body.");
            });
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            {
                string machineinfo;
                try
                {
                    UserConfig UC = (UserConfig)Session["UserConfig"];
                    machineinfo = "<span style=\"font-family:verdana;font-size=11px;\">Server:" + this.Server.MachineName + "<br>" +
                                  "User:"******"-" + UC.UserRealName + "<br>Agent: " + Request.UserAgent;
                    if (Request.UrlReferrer != null)
                    {
                        machineinfo += "<br>Referer: " + Request.UrlReferrer.ToString() + "<br>";
                    }
                }
                catch
                {
                    machineinfo = "Errore javascript.<br>";
                }
                string message = Request.QueryString["error"];

                MessagesHandler.SendMail(ConfigSettings.TustenaErrorMail, ConfigSettings.TustenaErrorMail, "[Tustena] Javascript Error", machineinfo + message + "</span>");
                SmtpEmailer emailer = new SmtpEmailer();
            }
        }
Example #8
0
        public static void SendMail(string mailTo, string mailFrom, string mailSubject, string mailBody)
        {
            SmtpEmailer emailer = new SmtpEmailer();

            emailer.Host = ConfigSettings.SMTPServer;
            try
            {
                emailer.Port = int.Parse(ConfigSettings.SMTPPort);
            }
            catch
            {
                emailer.Port = 25;
            }
            if (mailFrom == null)
            {
                emailer.From = ConfigSettings.TustenaMainMail;
            }
            else
            {
                emailer.From = mailFrom;
            }
            emailer.Subject = mailSubject;
            if (Regex.Match(mailBody, "</?\\w+\\s+[^>]*>").Success)
            {
                emailer.SendAsHtml = true;
            }
            else
            {
                emailer.SendAsHtml = false;
            }

            if (mailTo.IndexOf(';') > 0)
            {
                string[] to = mailTo.Split(';');
                foreach (string t in to)
                {
                    if (t.Length > 0)
                    {
                        emailer.To.Add(t);
                    }
                }
            }
            else
            {
                emailer.To.Add(mailTo);
            }
            emailer.Body = mailBody;
            switch (ConfigSettings.SpoolFormat)
            {
            case "mssmtp":
                emailer.SendIISSMTPMessage(ConfigSettings.MailSpoolPath);
                break;

            case "xmail":
                emailer.SendXMailMessage(ConfigSettings.MailSpoolPath);
                break;

            default:
                emailer.Host = ConfigSettings.SMTPServer;
                emailer.AuthenticationMode = AuthenticationType.Plain;
                if (ConfigSettings.SMTPAuthRequired)
                {
                    emailer.User     = ConfigSettings.SMTPUser;
                    emailer.Password = ConfigSettings.SMTPPassword;
                }
                emailer.SendMessageAsync();
                break;
            }
        }
Example #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddDbContext <ProjekatContext>();

            services.AddTransient <IGetGenresQuery, EfGetgenresCommand>();
            services.AddTransient <IAddGenreCommand, EfAddGenreCommand>();
            services.AddTransient <IDeleteGenreCommand, EfDeleteGenreCommand>();

            services.AddTransient <IGetCompaniesQuery, EfGetCompaniesCommand>();
            services.AddTransient <IAddCompanyCommand, EfAddCompanyCommand>();
            services.AddTransient <IDeleteCompanyCommand, EfDeleteCompanyCommand>();

            services.AddTransient <IGetConsolesQuery, EfGetConsolesCommand>();
            services.AddTransient <IAddConsoleCommand, EfAddConsoleCommand>();
            services.AddTransient <IDeleteConsoleCommand, EfDeleteConsolecommand>();

            services.AddTransient <IGetUsersQuery, EfGetUsersCommand>();
            services.AddTransient <IAddUserCommand, EfAddUserCommand>();
            services.AddTransient <IDeleteUserCommand, EfDeleteUserComand>();
            services.AddTransient <IEditUserCommand, EfEditUserCommand>();

            services.AddTransient <IGetGamesQuery, EfGetGamesCommand>();
            services.AddTransient <IAddGameCommand, EfAddGameCommand>();
            services.AddTransient <IDeleteGameCommand, EfDeleteGameCommand>();
            services.AddTransient <IEditGameCommand, EfEditGameCommand>();

            services.AddTransient <IGetRentQuery, EfGetRentsCommand>();
            services.AddTransient <IAddRentCommand, EfAddRentCommand>();

            var email   = Configuration.GetSection("Email");
            var emailer = new SmtpEmailer("stmp.gmail.com", 587, "*****@*****.**", "password");

            services.AddSingleton <IEmailer>(emailer);

            services.AddTransient <ILogInUserCommand, EfLogUserCommand>();
            var key = Configuration.GetSection("Encryption")["key"];
            var enc = new Encryption(key);

            services.AddSingleton(enc);

            services.AddTransient(s => {
                var http       = s.GetRequiredService <IHttpContextAccessor>();
                var value      = http.HttpContext.Request.Headers["Authorization"].ToString();
                var encryption = s.GetRequiredService <Encryption>();

                try
                {
                    var decoded   = encryption.DecryptString(value);
                    decoded       = decoded.Replace("\t", "");
                    var user      = JsonConvert.DeserializeObject <Logged>(decoded);
                    user.IsLogged = true;
                    return(user);
                }
                catch (Exception)
                {
                    return(new Logged
                    {
                        IsLogged = false
                    });
                }
            });
        }
Example #10
0
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            SmtpEmailer emailer = new SmtpEmailer();

            emailer.From       = MailAddressFrom.Text;
            emailer.Subject    = MailObject.Text;
            emailer.SendAsHtml = true;

            if (MailAddressTo.Text.Length > 0)
            {
                if (MailAddressTo.Text.IndexOf(';') > 1)
                {
                    string[] MailAddress = MailAddressTo.Text.Split(';');
                    foreach (string to in MailAddress)
                    {
                        emailer.To.Add(to);
                    }
                }
                else
                {
                    emailer.To.Add(MailAddressTo.Text);
                }
            }

            if (MailAddressCc.Text.Length > 0)
            {
                if (MailAddressCc.Text.IndexOf(';') > 1)
                {
                    string[] MailCc = MailAddressCc.Text.Split(';');
                    foreach (string to in MailCc)
                    {
                        emailer.CC.Add(to);
                    }
                }
                else
                {
                    emailer.To.Add(MailAddressCc.Text);
                }
            }

            if (MailAddressCcn.Text.Length > 0)
            {
                if (MailAddressCcn.Text.IndexOf(';') > 1)
                {
                    string[] MailCcn = MailAddressCcn.Text.Split(';');
                    foreach (string to in MailCcn)
                    {
                        emailer.BCC.Add(to);
                    }
                }
                else
                {
                    emailer.To.Add(MailAddressCcn.Text);
                }
            }



            emailer.Body = MailMessage.Text.Replace("\r", "").Replace("\n", "<br>");
            string filetodelete = "";

            if (this.IDDocument.Text.Length > 0)
            {
                DataTable dtAttach;
                dtAttach = DatabaseConnection.CreateDataset(String.Format("SELECT GUID,FILENAME FROM FILEMANAGER WHERE ID={0}", int.Parse(IDDocument.Text))).Tables[0];
                if (dtAttach.Rows.Count > 0)
                {
                    try
                    {
                        string dirPath;
                        string filePath;
                        dirPath  = ConfigSettings.DataStoragePath + Path.DirectorySeparatorChar + dtAttach.Rows[0]["guid"].ToString();
                        filePath = ConfigSettings.DataStoragePath + Path.DirectorySeparatorChar + dtAttach.Rows[0]["filename"].ToString();
                        FileFunctions.CheckDir(ConfigSettings.DataStoragePath, true);
                        if (File.Exists(dirPath + Path.GetExtension(dtAttach.Rows[0]["filename"].ToString())))
                        {
                            File.Copy(dirPath + Path.GetExtension(dtAttach.Rows[0]["filename"].ToString()), filePath);
                        }
                        else
                        {
                            File.Copy(dirPath, filePath);
                        }

                        SmtpAttachment att = new SmtpAttachment();
                        att.FileName    = filePath;
                        att.ContentType = "application/octet-stream";
                        att.Location    = AttachmentLocation.Attachment;
                        emailer.Attachments.Add(att);
                        filetodelete = filePath;
                    }
                    catch {}
                }
            }

            switch (ConfigSettings.SpoolFormat)
            {
            case "mssmtp":
                emailer.SendIISSMTPMessage(ConfigSettings.MailSpoolPath);
                break;

            case "xmail":
                emailer.SendXMailMessage(ConfigSettings.MailSpoolPath);
                break;

            default:
                emailer.Host = ConfigSettings.SMTPServer;
                emailer.AuthenticationMode = AuthenticationType.Plain;
                if (ConfigSettings.SMTPAuthRequired)
                {
                    emailer.User     = ConfigSettings.SMTPUser;
                    emailer.Password = ConfigSettings.SMTPPassword;
                }
                emailer.SendMessageAsync();
                break;
            }

            if (filetodelete.Length > 0)
            {
                File.Delete(filetodelete);
            }


            if (CreateActivity.Checked && MailAddressToID.Text.Length > 0)
            {
                ActivityInsert ai = new ActivityInsert();
                string         A  = "";
                string         C  = "";
                string         L  = "";

                switch (CrossWith.SelectedValue)
                {
                case "0":
                    A = MailAddressToID.Text;
                    C = "";
                    L = "";
                    break;

                case "1":
                    C = MailAddressToID.Text;
                    A = "";
                    L = "";
                    break;

                case "2":
                    L = MailAddressToID.Text;
                    A = "";
                    C = "";
                    break;
                }
                if (A.Length > 0 || C.Length > 0 || L.Length > 0)
                {
                    ai.InsertActivity("5", "", UC.UserId.ToString(), C, A, L, this.MailObject.Text, this.MailMessage.Text, UC.LTZ.ToUniversalTime(DateTime.Now), UC, 1);
                }
            }
            if (Session["fromtopbar"] != null)
            {
                Session.Remove("fromtopbar");
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + Root.rm.GetString("Mailtxt19") + "');self.close();</script>");
            }
            else if (Session["fromquick"] != null)
            {
                Session.Remove("fromquick");
                OnSendMail(true);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + Root.rm.GetString("Mailtxt19") + "');location.href='/mailinglist/webmail/webmail.aspx?m=46&dgb=1&si=63';</script>");
            }
        }