Пример #1
0
 /// <summary>
 /// Send email with attachment.
 /// </summary>
 /// <param name="fullPath">Full path of attaching file.</param>
 public void Send(string fullPath)
 {
     using (ISendingFile file = this._sendingFileCreator.Create(this.OurMail, this.TargetMail, fullPath))
     {
         this._mailSender.Send(file);
     }
 }
 public void SendWithAttach(ISendingFile attachFilePath)
 {
     try
     {
         _emailSender.SendWithAttach(attachFilePath);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
 public void DeleteFile(ISendingFile file)
 {
     try
     {
         File.Delete(file.Path);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #4
0
        /// <summary>
        /// Отправляет файл с вложением
        /// </summary>
        /// <param name="attachFile">Объект ISendingFile</param>
        public void SendWithAttach(ISendingFile attachFile)
        {
            try
            {
                _address      = _settingManager.GetParam("address").ToString();
                _from         = new MailAddress(_address, _settingManager.GetParam("displayName").ToString());
                _to           = new MailAddress(_address);
                _mail         = new MailMessage(_from, _to);
                _mail.Subject = _settingManager.GetParam("messageSubject").ToString();
                _mail.Body    = _settingManager.GetParam("messageBody").ToString();
                _mail.Attachments.Add(new Attachment(attachFile.Path));

                SmtpClient smtp = new SmtpClient(_settingManager.GetParam("host").ToString(), Convert.ToInt32(_settingManager.GetParam("port")));
                smtp.Credentials = new NetworkCredential(_addressSender, _passSender);
                smtp.EnableSsl   = true;

                smtp.Send(_mail);
                _mail.Dispose();
            }
            catch (ObjectDisposedException ex)
            {
                throw ex;
            }
            catch (InvalidOperationException ex)
            {
                throw ex;
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
            catch (SmtpFailedRecipientsException ex)
            {
                throw ex;
            }
            catch (SmtpException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
 /// <summary>
 /// Sends ISendingFile to email, specified at the time of its creation.
 /// </summary>
 /// <param name="sendingFile">Instance of ISendingFile to mail with its attachment.</param>
 public void Send(ISendingFile sendingFile)
 {
     this._smtpClient.Send(sendingFile.Message);
 }
Пример #6
0
 public FileWatcher(ISendingFile file)
 {
     _file             = file;
     _watcher          = new FileSystemWatcher();
     _watcher.Created += new FileSystemEventHandler(OnCreated);
 }