コード例 #1
0
ファイル: frmMailSet.cs プロジェクト: ymgw0867/guideRequest
        private void DataAddNew()
        {
            try
            {
                guideDataSet.メール設定Row r = (guideDataSet.メール設定Row)dts.メール設定.Newメール設定Row();

                r.ID        = global.mailKey;
                r.SMTPサーバー  = txtSmtpServerName.Text;
                r.SMTPポート番号 = utility.StrtoZero(txtSmtpPort.Text);
                r.POPサーバー   = txtPopServerName.Text;
                r.POPポート番号  = utility.StrtoZero(txtPopPort.Text);
                r.ログイン名     = txtLogin.Text;
                r.パスワード     = txtPassword.Text;
                r.メールアドレス   = txtFromAddress.Text;
                r.メール名称     = txtMailName.Text;
                r.受信間隔      = utility.StrtoZero(txtMailRecSpan.Text);
                r.署名        = txtMemo.Text;
                r.登録年月日     = DateTime.Now;
                r.更新年月日     = DateTime.Now;
                r.データ保存月数   = utility.StrtoZero(txtDataSaveMonth.Text);

                dts.メール設定.Addメール設定Row(r);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "エラーメッセージ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            finally
            {
            }

            MessageBox.Show("設定データが登録されました", "登録完了", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #2
0
        private void makeSendMail()
        {
            int mCnt = 0;

            for (int i = 0; i < dg1.RowCount; i++)
            {
                if (dg1["C_Check", i].Value.ToString() == "True")
                {
                    mCnt++;
                }
            }

            if (mCnt > 0)
            {
                // メール内容
                txtFrom.Enabled    = true;
                txtCc.Enabled      = true;
                txtBcc.Enabled     = true;
                txtSubject.Enabled = true;
                txtText.Enabled    = true;
                checkBox1.Enabled  = true;

                //
                guideDataSet.メール設定Row r = dts.メール設定.Single(a => a.ID == global.mailKey);

                if (!r.HasErrors)
                {
                    txtFrom.Text = r.メールアドレス;
                    txtCc.Text   = string.Empty;
                    txtBcc.Text  = string.Empty;

                    // メール定型文を呼び出す
                    StringBuilder         cSB = new StringBuilder(); // メール文面
                    mail.frmMailComSelect frm = new mail.frmMailComSelect(global.MLCOMMENT_IRAI);
                    frm.ShowDialog();
                    int mailComID = frm.mID;

                    if (mailComID != 0)
                    {
                        guideDataSet.メール定型文Row cr = dts.メール定型文.Single(a => a.ID == mailComID);

                        if (!cr.HasErrors)
                        {
                            // 件名
                            txtSubject.Text = cr.件名 + " " + selNum.ToString();

                            // 前文
                            cSB.Append(cr.前文).Append(Environment.NewLine);

                            // 内容
                            cSB.Append("依頼番号:").Append(selNum.ToString()).Append(Environment.NewLine).Append(Environment.NewLine);
                            cSB.Append("稼働日:").Append(dateTimePicker2.Value.ToLongDateString()).Append(Environment.NewLine).Append(Environment.NewLine);
                            cSB.Append("依頼元:").Append(cmbIrai.Text).Append(" 様").Append(Environment.NewLine).Append(Environment.NewLine);
                            cSB.Append("内容:").Append(txtName.Text).Append(Environment.NewLine).Append(Environment.NewLine);
                            cSB.Append("特記事項:").Append(txtMemo.Text).Append(Environment.NewLine).Append(Environment.NewLine);

                            // 後文
                            cSB.Append(cr.後文).Append(Environment.NewLine);

                            // 署名を付加
                            cSB.Append(r.署名);

                            // メール文章
                            txtText.Text = cSB.ToString();

                            // メール送信ボタン
                            linkLabel5.Visible = true;
                            linkLabel6.Visible = true;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("メール送信対象者がいません", "確認", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
        }
コード例 #3
0
        ///-----------------------------------------------------------------------------
        /// <summary>
        ///     依頼メールを送信する </summary>
        /// <param name="toAddress">
        ///     宛先アドレス</param>
        /// <param name="sSubject">
        ///     メール件名</param>
        /// <param name="sMailText">
        ///     メール本文</param>
        /// <param name="SubjectOp">
        ///     </param>
        /// <param name="toStatus">
        ///     true:宛名差し込みする、false:宛名差し込みしない</param>
        /// <param name="testFlg">
        ///     0:本番送信、1:テスト送信</param>
        ///-----------------------------------------------------------------------------
        private void sendRequestMail(string toAddress, string sSubject, string sMailText, string SubjectOp, bool toStatus, int testFlg)
        {
            // メール設定情報
            guideDataSet.メール設定Row r = dts.メール設定.Single(a => a.ID == global.mailKey);

            // smtpサーバーを指定する
            SmtpClient client = new SmtpClient();

            client.Host           = r.SMTPサーバー;
            client.Port           = r.SMTPポート番号;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials    = new System.Net.NetworkCredential(r.ログイン名, r.パスワード);
            client.EnableSsl      = false;
            client.Timeout        = 10000;

            //メッセージインスタンス生成
            MailMessage message = new MailMessage();

            //送信元
            message.From = new MailAddress(r.メールアドレス, r.メール名称);

            //件名
            message.Subject = sSubject;

            // Cc
            if (txtCc.Text != string.Empty)
            {
                message.CC.Add(new MailAddress(txtCc.Text));
            }

            // Bcc
            if (txtBcc.Text != string.Empty)
            {
                message.Bcc.Add(new MailAddress(txtBcc.Text));
            }

            // 送信メールカウント
            int mCnt = 0;

            try
            {
                // 送信先テストモード
                if (Properties.Settings.Default.mailTest == global.FLGON)
                {
                    // テスト送信先
                    string[] toAdd = { "*****@*****.**", "*****@*****.**", "*****@*****.**" };

                    for (int i = 0; i < toAdd.Length; i++)
                    {
                        // 宛先
                        message.To.Clear();
                        message.To.Add(new MailAddress(toAdd[i]));

                        // 複数送信の時、2件目以降のCc/Bcc設定はクリアする
                        if (mCnt > 0)
                        {
                            message.CC.Clear();
                            message.Bcc.Clear();
                        }

                        // 送信する
                        client.Send(message);

                        // 送信ログ書き込み
                        DateTime nDt = DateTime.Now;
                        mllogUpdate("", toAdd[i], r.メール名称, r.メールアドレス, sSubject, sMailText, nDt);

                        // カウント
                        mCnt++;
                    }
                }
                else if (Properties.Settings.Default.mailTest == global.FLGOFF)
                {
                    // 本番用:グリッドから送付先を読み込む
                    for (int i = 0; i < dg1.RowCount; i++)
                    {
                        // チェック行
                        if (dg1["C_Check", i].Value.ToString() == "True")
                        {
                            // メールアドレスの記入あり
                            if (dg1[C_Mail, i].Value != null)
                            {
                                string toAdd  = "";
                                string toName = "";

                                // テスト?本送信?
                                if (testFlg == global.FLGOFF)
                                {
                                    // 本送信
                                    toAdd  = dg1[C_Mail, i].Value.ToString();
                                    toName = utility.NulltoStr(dg1[C_Name, i].Value);
                                }
                                else if (testFlg == global.FLGON)
                                {
                                    // テスト送信
                                    toAdd  = r.メールアドレス;
                                    toName = r.メール名称;
                                }

                                //宛先
                                message.To.Clear();
                                message.To.Add(new MailAddress(toAdd, toName));

                                // 複数送信の時、2件目以降のCc/Bcc設定はクリアする
                                if (mCnt > 0)
                                {
                                    message.CC.Clear();
                                    message.Bcc.Clear();
                                }

                                //本文
                                if (toStatus)
                                {
                                    // 宛名氏名を差し込む
                                    string toSama = dg1[C_Name, i].Value.ToString() + " 様" + Environment.NewLine + Environment.NewLine;
                                    message.Body = toSama + sMailText;
                                }
                                else
                                {
                                    message.Body = sMailText;
                                }

                                // 送信する
                                client.Send(message);

                                // 本送信のとき
                                if (testFlg == global.FLGOFF)
                                {
                                    DateTime nDt = DateTime.Now;

                                    // ガイド依頼名テーブルに送信日時を書き込む
                                    iraiMLSendDateUpdate(nDt);

                                    // 対象者データに送信日時を書き込む
                                    guideSendUpdate(int.Parse(dg1[C_Key, i].Value.ToString()), nDt);

                                    // 送信ログ書き込み
                                    mllogUpdate(toName, toAdd, r.メール名称, r.メールアドレス, sSubject, sMailText, nDt);
                                }
                                // カウント
                                mCnt++;
                            }
                        }
                    }
                }
            }
            catch (SmtpException ex)
            //catch (Exception ex)
            {
                //エラーメッセージ
                MessageBox.Show(ex.Message, "メール送信エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                // 送信あり
                if (mCnt > 0)
                {
                    MessageBox.Show(mCnt.ToString() + "件の依頼メールを送信しました");

                    // 本送信の時
                    if (testFlg == global.FLGOFF)
                    {
                        // データベース更新
                        lAdp.Update(dts.メール送受信記録);
                        gAdp.Update(dts.ガイド依頼対象者);
                        adp.Update(dts.ガイド依頼名);
                    }
                }

                message.Dispose();
            }
        }
コード例 #4
0
        ///----------------------------------------------------------
        /// <summary>
        ///     メール作成 </summary>
        ///----------------------------------------------------------
        private void makeSendMail()
        {
            // メール内容
            txtFrom.Enabled    = true;
            txtCc.Enabled      = true;
            txtBcc.Enabled     = true;
            txtSubject.Enabled = true;
            txtText.Enabled    = true;

            //
            guideDataSet.メール設定Row r = dts.メール設定.Single(a => a.ID == global.mailKey);

            if (!r.HasErrors)
            {
                txtFrom.Text = r.メールアドレス;
                txtCc.Text   = string.Empty;
                txtBcc.Text  = string.Empty;

                // メール定型文を呼び出す
                StringBuilder    cSB = new StringBuilder(); // メール文面
                frmMailComSelect frm = null;

                if (comboBox2.SelectedIndex == 0)
                {
                    frm = new frmMailComSelect(global.MLCOMMENT_KETTEI);
                }
                else if (comboBox2.SelectedIndex == 1)
                {
                    frm = new frmMailComSelect(global.MLCOMMENT_KOTOWARI);
                }

                frm.ShowDialog();
                int mailComID = frm.mID;

                if (mailComID != 0)
                {
                    guideDataSet.メール定型文Row cr = dts.メール定型文.Single(a => a.ID == mailComID);

                    if (!cr.HasErrors)
                    {
                        // 件名
                        txtSubject.Text = cr.件名;

                        // 前文
                        cSB.Append(cr.前文).Append(Environment.NewLine);

                        // 内容
                        cSB.Append("依頼番号:").Append(txtIraiNum.Text).Append(Environment.NewLine).Append(Environment.NewLine);
                        cSB.Append("稼働日:").Append(DateTime.Parse(txtWdate.Text).ToLongDateString()).Append(Environment.NewLine).Append(Environment.NewLine);
                        cSB.Append("依頼元:").Append(txtIrai.Text).Append(" 様").Append(Environment.NewLine).Append(Environment.NewLine);
                        cSB.Append("内容:").Append(txtName.Text).Append(Environment.NewLine).Append(Environment.NewLine);
                        cSB.Append("特記事項:").Append(txtMemo.Text).Append(Environment.NewLine).Append(Environment.NewLine);

                        // 後文
                        cSB.Append(cr.後文).Append(Environment.NewLine);

                        // 署名を付加
                        cSB.Append(r.署名);

                        // メール文章
                        txtText.Text = cSB.ToString();

                        // メール送信ボタン
                        linkLabel6.Visible = true;
                        linkLabel5.Visible = true;

                        // 組合員名自動不可
                        checkBox1.Checked = true;
                    }
                }
            }
        }