Esempio n. 1
0
        ///--------------------------------------------------------------------------
        /// <summary>
        ///     メール設定登録確認 </summary>
        /// <returns>
        ///     true:登録済み, false:未登録</returns>
        ///--------------------------------------------------------------------------
        private bool hpStatus()
        {
            confirDataSet dts = new confirDataSet();

            confirDataSetTableAdapters.メール設定TableAdapter mAdp = new confirDataSetTableAdapters.メール設定TableAdapter();

            mAdp.Fill(dts.メール設定);

            // メール設定が登録済みか?
            if (dts.メール設定.Count() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        ///-----------------------------------------------------------------------------
        /// <summary>
        ///     依頼メールを送信する </summary>
        /// <param name="attachFile">
        ///     添付ファイル名</param>
        /// <param name="sSubject">
        ///     件名</param>
        /// <param name="sBody">
        ///     メール本文</param>
        /// <param name="msg">
        ///     メッセージ</param>
        /// <param name="testFlg">
        ///     0:本番送信、1:テスト送信</param>
        ///-----------------------------------------------------------------------------
        public static void sendKintaiMail(string attachFile, string sSubject, string sBody, string msg, int testFlg)
        {
            confirDataSet dts = new confirDataSet();

            confirDataSetTableAdapters.メール設定TableAdapter adp = new confirDataSetTableAdapters.メール設定TableAdapter();
            adp.Fill(dts.メール設定);

            // メール設定情報
            if (!dts.メール設定.Any(a => a.ID == global.mailKey))
            {
                MessageBox.Show("メール設定情報が未登録のためメール送信はできません", "メール設定未登録", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            confirDataSet.メール設定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;

            string toAdd  = "";
            string toName = "";

            try
            {
                toAdd  = r.送信先アドレス;
                toName = "";

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

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

                //本文
                message.Body = sBody;

                // 添付ファイル・勤怠データ
                Attachment att = new Attachment(attachFile, "text/csv");
                message.Attachments.Add(att);

                message.BodyEncoding = System.Text.Encoding.GetEncoding(50220);

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

                // 本送信のとき
                if (testFlg == global.flgOff)
                {
                    MessageBox.Show(msg + "を送信しました", "結果", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    // ログ書き込み
                    putMaillog(toAdd, sSubject, "送信しました");
                }

                // カウント
                mCnt++;
            }
            catch (SmtpException ex)
            {
                //エラーメッセージ
                string errMsg = ex.Message + Environment.NewLine + Environment.NewLine + "メール情報設定画面で設定内容を確認してください。その後、再実行してください。";
                MessageBox.Show(errMsg, "メール送信失敗", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                // ログ書き込み
                putMaillog(toAdd, sSubject, ex.Message);
            }
            finally
            {
                //// 送信あり
                //if (mCnt > 0)
                //{
                //    MessageBox.Show(mCnt.ToString() + "件の出勤簿メールを送信しました");

                //    // 本送信の時
                //    if (testFlg == global.flgOff)
                //    {
                //        // ログ書き込み
                //        putMaillog(toAdd, sSubject, "送信しました");
                //    }
                //}

                // 後片付け
                message.Dispose();
            }
        }