コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var tmpfilepath = new string[] {
                AppDomain.CurrentDomain.BaseDirectory + @"\attach\test.txt",
                AppDomain.CurrentDomain.BaseDirectory + @"\attach\test.zip"
            };

            apiol.sendmail("*****@*****.**", "*****@*****.**", " a test from client", "This is a test, It should work.....", tmpfilepath, "OK");
        }
コード例 #2
0
ファイル: SendEmailByXls.cs プロジェクト: xlgwr/hr
        private void btn2GoUploadToERP_Click(object sender, EventArgs e)
        {
            try
            {
                if (_guserMstrList.Count <= 0)
                {
                    btn3QuickUploadExcel.Focus();
                    this.AcceptButton = btn3QuickUploadExcel;
                    return;
                }
                this.AcceptButton = btn2GoUploadToERP;
                #region check

                if (string.IsNullOrEmpty(txt2Subject.Text))
                {
                    txt2Subject.Focus();
                    lbl1UploadExcelThreadMsg.Text = "Notice: Please enter Subject.";
                    return;
                }
                else if (txt1ZipPath.Text.Trim() == "")
                {
                    apisharp.setControlText <SendEmailByXls>(this, lbl1UploadExcelThreadMsg, "Error,Please Set a Path (Excel file) to Zip!", true, true);
                    btn0SetZip.Focus();
                    return;
                }
                else if (string.IsNullOrEmpty(txt5Body.Text))
                {
                    if (MessageBox.Show("Body is Nothing,Are you Conitnue?", "Notice", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                    {
                        txt5Body.Focus();
                        lbl1UploadExcelThreadMsg.Text = "Notice: Please enter Body.";
                        return;
                    }
                }
                #endregion
                btnEnable(false, true, false);
                //start outolook

                #region dotnetzip sample password

                var tmpmsg   = "";
                var tmpfiles = txt1ZipPath.Text.Trim();

                List <string> filelist_al = new List <string>();
                var           tmpfilesZip = tmpfiles + @"Zip\";

                DirectoryInfo thisdir  = new DirectoryInfo(tmpfiles);
                FileInfo[]    filelist = thisdir.GetFiles();

                if (!Directory.Exists(tmpfilesZip))
                {
                    Directory.CreateDirectory(tmpfilesZip);
                }
                //init
                int    tmpcountsuccess = 0;
                int    tmpnoxlsfile    = 0;
                int    tmperrorcount   = 0;
                string errmsg          = "";

                foreach (FileInfo item in filelist)
                {
                    if (item.Extension.Equals(".zip"))
                    {
                        continue;
                    }
                    if (item.Name.Length < _tidLength)
                    {
                        //lbl1UploadExcelThreadMsg.Text = "User ID is to Long than file Name:" + item.Name;
                        if (string.IsNullOrEmpty(errmsg))
                        {
                            errmsg = item.Name;
                        }
                        else
                        {
                            errmsg += "," + item.Name;
                        }
                        tmperrorcount++;
                        continue;
                    }
                    var fileuserid = item.Name.Substring(0, _tidLength);

                    var finduserid = _guserMstrList.Where(p => p.userID.Equals(fileuserid)).SingleOrDefault();

                    if (finduserid != null)
                    {
                        var tmpitemzip = tmpfilesZip + finduserid.userID + ".zip";

                        var sf = apizip.CompressFilesWithZip(item.FullName, tmpitemzip, finduserid.password, finduserid.userID);
                        if (sf)
                        {
                            _gzipfilepath.Add(new savezipfile(finduserid.userID, tmpitemzip));
                            //send mail
                            var tmpfilepath = new string[] { tmpitemzip };
                            tmpmsg = "Sending: " + finduserid.userID + "," + finduserid.name + "," + finduserid.email + " of email.";
                            apisharp.setControlText <SendEmailByXls>(this, lbl1UploadExcelThreadMsg, tmpmsg, true, true);
                            lbl1UploadExcelThreadMsg.Text = tmpmsg;

                            var tmpcc = finduserid.cc_super + ";" + finduserid.cc_hr;
                            apiol.sendmail(finduserid.email, tmpcc, txt2Subject.Text, txt5Body.Text, tmpfilepath, "Ok");
                            finduserid.attach = tmpitemzip;
                            tmpcountsuccess++;
                        }
                    }
                    //filelist_al.Add(item.FullName.ToString());
                }
                tmpnoxlsfile = _guserMstrList.Where(p => string.IsNullOrEmpty(p.attach)).Count();

                tmpmsg = "Send OK. Total User:"******",\n Total Success Send:" + tmpcountsuccess + ".";

                if (tmpnoxlsfile > 0)
                {
                    tmpmsg += " \n Total No Zip(Excel) File: " + tmpnoxlsfile + ".";
                }

                if (!string.IsNullOrEmpty(errmsg))
                {
                    tmpmsg += "\n User ID is to Long than file Name:" + errmsg + ".";
                }

                apisharp.setControlText <SendEmailByXls>(this, lbl1UploadExcelThreadMsg, tmpmsg.Replace("\n", ""), true, true);
                MessageBox.Show(tmpmsg, "Notice");

                //show email

                data1GV1ePackingDet1UploadExcel.DataSource = _guserMstrList;
                data1GV1ePackingDet1UploadExcel.Refresh();
                btnEnable(true, true, true);


                #endregion
            }
            catch (Exception ex)
            {
                btnEnable(true, true, true);
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        private void btn0Send_Click(object sender, EventArgs e)
        {
            _guserMstrList = new List <user_mstr>();
            _gzipfilepath  = new List <savezipfile>();
            var tmpmsg = "";

            #region check
            if (string.IsNullOrEmpty(txt0To.Text))
            {
                txt0To.Focus();
                tool0Msg.Text = "Notice: 请输入收件人.";
                return;
            }
            if (string.IsNullOrEmpty(txt1ToCC.Text))
            {
                txt1ToCC.Focus();
                tool0Msg.Text = "Notice: 请输入抄送人.";
                return;
            }
            if (string.IsNullOrEmpty(txt2Subject.Text))
            {
                txt2Subject.Focus();
                tool0Msg.Text = "Notice: 请输入主题.";
                return;
            }
            if (string.IsNullOrEmpty(txt3Addtchedfilepath.Text))
            {
                btn1Files.Focus();
                tool0Msg.Text = "Notice: 请设置附件文件夹.";
                return;
            }
            #endregion

            var tmpOemail = txt0To.Text.Trim().Split(';');

            if (tmpOemail.Count() < 0)
            {
                txt0To.Focus();
                return;
            }
            tmpmsg           = "开始发送.";
            tool0Msg.Text    = tmpmsg;
            btn0Send.Enabled = false;
            foreach (var item in tmpOemail)
            {
                var tmpuser = _hrzip.user_mstr.Where(p => p.email.Equals(item.Trim())).SingleOrDefault();
                if (tmpuser != null)
                {
                    _guserMstrList.Add(tmpuser);
                }
            }
            #region dotnetzip sample password

            var           tmpfiles    = txt3Addtchedfilepath.Text.Trim();
            List <string> filelist_al = new List <string>();
            var           tmpfilesZip = tmpfiles + @"Zip\";

            DirectoryInfo thisdir  = new DirectoryInfo(tmpfiles);
            FileInfo[]    filelist = thisdir.GetFiles();

            if (!Directory.Exists(tmpfilesZip))
            {
                Directory.CreateDirectory(tmpfilesZip);
            }
            //init

            foreach (FileInfo item in filelist)
            {
                if (item.Extension.Equals(".zip"))
                {
                    continue;
                }
                foreach (var userid in _guserMstrList)
                {
                    var fileuserid = item.Name.Split('.')[0].Split('-')[0];
                    if (fileuserid.Equals(userid.userID))
                    {
                        var tmpitemzip = tmpfilesZip + userid.userID + ".zip";

                        var sf = apizip.CompressFilesWithZip(item.FullName, tmpitemzip, userid.password, userid.userID);
                        if (sf)
                        {
                            _gzipfilepath.Add(new savezipfile(userid.userID, tmpitemzip));
                            //send mail
                            var tmpfilepath = new string[] { tmpitemzip };
                            tmpmsg        = "正在发送: " + userid.userID + "," + userid.name + "," + userid.email + " 的邮件.";
                            tool0Msg.Text = tmpmsg;
                            apiol.sendmail(userid.email, txt1ToCC.Text, txt2Subject.Text, txt5Body.Text, tmpfilepath, "Ok");
                        }
                    }
                }
                //filelist_al.Add(item.FullName.ToString());
            }
            tmpmsg        = "发送完成.";
            tool0Msg.Text = tmpmsg;
            MessageBox.Show(tmpmsg);
            btn0Send.Enabled = true;
            #endregion
        }