Beispiel #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (txtEmailSubject.Text == "")
            {
                MessageBox.Show("Subject is empty.");
                return;
            }

            if (string.IsNullOrEmpty(cmbEmailField.Text))
            {
                MessageBox.Show("email field is invalid.");
                return;
            }

            var textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
            var app = new OutlookEmailerLateBinding();
            var replacements = GetReplacementList(txtEmailBody.Text);
            foreach (ListViewItem studentId in lstEmailSendSelection.Items)
            {
                if (!studentId.Checked)
                    continue;

                var row = (DataRow)studentId.Tag;
                try
                {
                    var emailtext = replaceFields(txtEmailBody.Text, replacements, row);
                    var emailSubject = replaceFields(txtEmailSubject.Text, replacements, row);

                    var destEmail = row[cmbEmailField.Text].ToString();
                    if (chkEmailDryRun.Checked)
                        app.SendOutlookEmail("*****@*****.**", emailSubject, emailtext, txtEmailCC.Text);
                    else
                        app.SendOutlookEmail(destEmail, emailSubject, emailtext, txtEmailCC.Text);

                }
                catch (Exception ex)
                {

                    MessageBox.Show(ex.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            MessageBox.Show("Done.");
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (txtEmailSubject.Text == "")
            {
                MessageBox.Show("Subject is empty.");
                return;
            }

            var mcalc = _config.GetMarkCalculator();

            var textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
            var app = new OutlookEmailerLateBinding();
            var replacements = GetReplacementList(txtEmailBody.Text);
            foreach (ListViewItem studentId in lstEmailSendSelection.Items)
            {
                if (!studentId.Checked)
                    continue;

                var iStudentId = (int)studentId.Tag;
                DataRow row;
                var emailtext = Emailtext(replacements, iStudentId, mcalc, out row);
                var DestEmail = row["SUB_email"].ToString();

                if (!chkEmailDryRun.Checked)
                    app.SendOutlookEmail(DestEmail, txtEmailSubject.Text, emailtext);
                else
                    Debug.WriteLine(emailtext);
            }

            MessageBox.Show("Done");
        }
Beispiel #3
0
        private void SendMail_Click(object sender, EventArgs e)
        {
            var v = MessageBox.Show("Ready to send emails?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
            if (v != DialogResult.Yes)
                return;

            var sql = "select * from Qemails";
            var studs = clsConfig.GetDataTable(sql);

            var textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
            var app = new OutlookEmailerLateBinding();

            foreach (DataRow row in studs.Rows)
            {
                var destEmail = row["email"].ToString();
                var emailtext = emailBody;

                //string sname = row["name"].ToString().ToLower();
                //string wholename = textInfo.ToTitleCase(sname);
                //string[] wholenames = wholename.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var firstnames = row["FirstName"].ToString().ToLower();
                var firstnamesA = firstnames.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var firstname = firstnamesA[0];

                var thisId = (int)row["Stud_Id"];

                emailtext = emailtext.Replace("{FirstName}", textInfo.ToTitleCase(firstname));
                emailtext = emailtext.Replace("{Feedback}", clsConfig.GetStudentReport(thisId, false));
                txtReport.Text += emailtext;
                txtReport.Text += "\r\n====================\r\n";
                app.SendOutlookEmail(destEmail, "BE1013 mark", emailtext);
            }
        }