示例#1
0
 public bool setHost(Hosts h)
 {
     foreach (var _ in h)
     {
         if (_.code == code)
         {
             this.Host = _;
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        public bool Send()
        {
            MailMessage _msg = new MailMessage();

            _msg.From = new MailAddress(From.Address, From.name);
            foreach (var t in To)
            {
                _msg.To.Add(new MailAddress(t.Address, t.name));
            }

            foreach (var a in files)
            {
                _msg.Attachments.Add(a);
            }
            _msg.Body    = Msg;
            _msg.Subject = Subject;
            Host h = From.Host ?? Hosts.GetHost(From);

            if (h == null)
            {
                if (OnFail != null)
                {
                    OnFail(this, "host not defined");
                }
                return(false);
            }
            SmtpClient smtp = From.Host.SMTP;

            From.SetAuth(smtp);
            try
            {
                smtp.Send(_msg);
                if (OnSuccess != null)
                {
                    OnSuccess(this);
                }
                return(true);
            }
            catch (Exception e)
            {
                if (OnFail != null)
                {
                    OnFail(this, "host not defined");
                }
                return(false);
            }
        }