private void SendMail(SmtpClient client) { if (_entEmail == null || _entReceiver == null) { return; } if (_entEmail.EML_SERNO == "" || !_entReceiver.readFirst()) { return; } MailAddressCollection to = new MailAddressCollection(), cc = new MailAddressCollection(); try { do { if (_entReceiver.ERC_TYPE == "C") { cc.Add(new MailAddress(_entReceiver.ERC_EMAIL, _entReceiver.ERC_NAME)); } else { to.Add(new MailAddress(_entReceiver.ERC_EMAIL, _entReceiver.ERC_NAME)); } }while (_entReceiver.read()); if (to.Count == 0) { WriteEmailLog(_entEmail.EML_SERNO, Message1, "E"); return; } MailMessage mail = new MailMessage(); mail.From = new MailAddress(UserEmail, UserName); foreach (MailAddress m in to) { mail.To.Add(m); } foreach (MailAddress m in cc) { mail.CC.Add(m); } mail.Subject = _entEmail.EML_TITLE; mail.Body = _entEmail.EML_CONTENT; //attachment if (_entFile.readFirst()) { ArrayList s = new ArrayList(); do { if (_attachmentFile[_entFile.ULF_SERNO.Value] == null) { s.Add(_entFile.ULF_SERNO.Value); } else { mail.Attachments.Add((Attachment)_attachmentFile[_entFile.ULF_SERNO.Value]); } } while (_entFile.read()); if (s.Count > 0) { DocumentFile entDoc = new DocumentFile(_conn); entDoc.query(null, entDoc.ULF_SERNO.cds_EqualIn((string[])s.ToArray(typeof(string))), "", ""); UploadFileObj fObj = new UploadFileObj(entDoc, entDoc.ULF_FILE); Attachment att; MemoryStream fs; while (entDoc.read()) { fs = new MemoryStream(); fObj.ToStream(fs); att = new Attachment(fs, entDoc.ULF_FILENAME, MediaTypeNames.Application.Octet); mail.Attachments.Add(att); _attachmentFile[entDoc.ULF_SERNO.Value] = att; } } } client.Send(mail); WriteEmailLog(_entEmail.EML_SERNO, "郵件寄出", "S"); } catch (Exception ex) { WriteEmailLog(_entEmail.EML_SERNO, ex.Message, "E"); return; } }