Exemple #1
0
 public static void TestSend(EmailSend es, string title, string content)
 {
     if (es.Send(title, content))
     {
         Console.WriteLine("发送成功");
     }
     else
     {
         Console.WriteLine("发送失败");
     }
 }
Exemple #2
0
        public void Send()
        {
            EmailSend email = new EmailSend();

            email.Subject = this.subject;
            email.Body    = this.body;
            List <string> to = new List <string>();

            foreach (var item in this.rcverList)
            {
                string str = item.EmailName;
                to.Add(str);
            }
            email.EmailTo = to;

            if (this.attList.Count > 0)
            {
                List <string> attStrList = new List <string>();
                foreach (object item in this.attList)
                {
                    string fileName = (string)item;
                    attStrList.Add(fileName);
                }
                email.AttFileName = attStrList;
            }

            if (to.Count == 0)
            {
                this.Hint = "收件人不能为空!";
            }
            else
            {
                email.Send();
                this.Hint = "邮件发送成功!";
            }
        }
Exemple #3
0
        public void OneKeySend()
        {
            if (this.SendList == null || this.SendList.Count == 0)
            {
                this.Hint = "请至少选择一个分发产品!";
                return;
            }

            if (this.EmailOptions != null && this.EmailOptions.Count > 0)
            {
                this.Hint = "Email发送中...";
                EmailSend email = new EmailSend();
                email.EmailTo = new List <string>();
                foreach (var item in this.EmailOptions)
                {
                    if (item.IsSelected == true)
                    {
                        email.EmailTo.Add(item.Address.EmailName);
                    }
                }
                email.Subject     = "";
                email.AttFileName = new List <string>();
                foreach (var item in this.SendList)
                {
                    email.AttFileName.Add(item);
                    FileInfo fi = new FileInfo(item);
                    if (fi.Extension.Equals(".doc") || fi.Extension.Equals(".docx"))
                    {
                        string name = Path.GetFileNameWithoutExtension(item);
                        email.Subject = name;
                        break;
                    }
                    email.Subject += new FileInfo(item).Name + " | ";
                }

                if (email.EmailTo.Count > 0)
                {
                    email.Send();
                }
                this.Hint = "Email发送完成!";
            }

            if (this.NotesOptions != null && this.NotesOptions.Count > 0)
            {
                this.Hint = "Notes发送中...";
                NotesSend notes = new NotesSend();
                notes.MailTo = new List <string>();
                foreach (var item in this.NotesOptions)
                {
                    if (item.IsSelected == true)
                    {
                        notes.MailTo.Add(item.Address.NotesName);
                    }
                }
                notes.Subject     = "";
                notes.AttFileName = new List <string>();
                foreach (var item in this.SendList)
                {
                    notes.AttFileName.Add(item);
                    FileInfo fi = new FileInfo(item);
                    if (fi.Extension.Equals(".doc") || fi.Extension.Equals(".docx"))
                    {
                        string name = Path.GetFileNameWithoutExtension(item);
                        notes.Subject = name;
                        break;
                    }
                    notes.Subject += new FileInfo(item).Name + " | ";
                }

                if (notes.MailTo.Count > 0)
                {
                    notes.SendMail();
                }
                this.Hint = "Notes发送完成!";
            }

            if (this.ftpOptions != null && this.ftpOptions.Count > 0)
            {
                this.Hint = "FTP上传中...";
                foreach (var op in this.ftpOptions)
                {
                    if (op.IsSelected == true)
                    {
                        foreach (var file in this.SendList)
                        {
                            string newName = Path.GetFileName(new FileInfo(file).Name);

                            FtpUpload ftpUpload = new FtpUpload(op.Address.FtpPath, file, newName);
                            if (op.Address.FtpUserName != null && (!op.Address.FtpUserName.Trim().Equals(string.Empty)))
                            {
                                ftpUpload.User = op.Address.FtpUserName.Trim();
                            }

                            if (op.Address.FtpPwd != null && (!op.Address.FtpPwd.Trim().Equals(string.Empty)))
                            {
                                ftpUpload.Pwd = op.Address.FtpPwd.Trim();
                            }

                            try
                            {
                                ftpUpload.Upload();
                            }
                            catch (Exception)
                            {
                                this.Hint = "FTP文件上传失败,请检查FTP设置!";
                            }
                        }
                    }
                }

                this.Hint = "FTP上传完成!";
            }

            if (this.lanOptions != null && this.lanOptions.Count > 0)
            {
                this.Hint = "局域网上传中...";
                foreach (var op in this.lanOptions)
                {
                    if (op.IsSelected == true)
                    {
                        foreach (var file in this.SendList)
                        {
                            LanSend lanSend = new LanSend(file.Trim(), op.Address.LanPath.Trim());

                            if (op.Address.LanName != null && (!op.Address.LanName.Trim().Equals(string.Empty)))
                            {
                                lanSend.UserName = op.Address.LanName.Trim();
                            }

                            if (op.Address.LanPwd != null && (!op.Address.LanPwd.Trim().Equals(string.Empty)))
                            {
                                lanSend.Pwd = op.Address.LanPwd.Trim();
                            }

                            if (lanSend.SendFile() != true)
                            {
                                this.Hint = file +   "上传失败!";
                            }
                        }
                    }
                }

                this.Hint = "局域网上传完成!";
                this.Hint = "一键分发完成!";
            }
        }