| | |
| | | using System;
|
| | | using System.Data.OracleClient;
|
| | | using System.Net;
|
| | | using System.Net.Mail;
|
| | |
|
| | | namespace CCSTrace.CCS.Function
|
| | | {
|
| | | public class MailService
|
| | | {
|
| | | private SmtpClient smtpClient = null;
|
| | | private string SMTP_IP;
|
| | | private int SMTP_Port;
|
| | | private string EMailAddr;
|
| | | private string EMailPass;
|
| | | private string ToEMail;
|
| | | private SmtpClient _smtpClient;
|
| | | private string _smtpIp;
|
| | | private int _smtpPort;
|
| | | private string _eMailAddr;
|
| | | private string _eMailPass;
|
| | | private string _toEMail;
|
| | |
|
| | | public MailService(OracleConnection _Conn)
|
| | | public MailService(OracleConnection conn)
|
| | | {
|
| | | InitialSmtpClient(_Conn);
|
| | | InitialSmtpClient(conn);
|
| | | }
|
| | |
|
| | | public void InitialSmtpClient(OracleConnection _Conn)
|
| | | public void InitialSmtpClient(OracleConnection conn)
|
| | | {
|
| | | getMailSetting(_Conn);
|
| | | smtpClient = new SmtpClient(SMTP_IP, SMTP_Port);
|
| | | smtpClient.Credentials = new System.Net.NetworkCredential(EMailAddr, EMailPass);
|
| | | smtpClient.EnableSsl = false;
|
| | | GetMailSetting(conn);
|
| | | _smtpClient = new SmtpClient(_smtpIp, _smtpPort)
|
| | | {
|
| | | Credentials = new NetworkCredential(_eMailAddr, _eMailPass),
|
| | | EnableSsl = false
|
| | | };
|
| | | }
|
| | |
|
| | | public bool SendMail(String CCSID)
|
| | | public bool SendMail(string ccsid)
|
| | | {
|
| | | Attachment objAttFle = new Attachment(CCS.LocalVariable.CCS_ListPath + CCSID + ".txt");
|
| | | Attachment objAttFle = new Attachment(GlobalVariable.CcsListPath + ccsid + ".txt");
|
| | | MailMessage objMail = new MailMessage();
|
| | |
|
| | | try
|
| | | {
|
| | | objMail.From = new MailAddress(EMailAddr);
|
| | | objMail.To.Add(ToEMail);
|
| | | objMail.From = new MailAddress(_eMailAddr);
|
| | | objMail.To.Add(_toEMail);
|
| | |
|
| | | objMail.BodyEncoding = System.Text.Encoding.UTF8;
|
| | | objMail.Subject = "CCS事故案件追蹤失敗";
|
| | | //objMail.Body = "測試收件者"; |
| | | //objMail.Body = "測試收件者";
|
| | | objMail.IsBodyHtml = true;
|
| | |
|
| | | if ( objAttFle != null )
|
| | | if (objAttFle != null)
|
| | | objMail.Attachments.Add(objAttFle);
|
| | |
|
| | | smtpClient.Send(objMail);
|
| | | _smtpClient.Send(objMail);
|
| | | return true;
|
| | | }
|
| | | catch
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private void getMailSetting(OracleConnection _Conn)
|
| | | private void GetMailSetting(OracleConnection conn)
|
| | | {
|
| | | String SqlStmt;
|
| | | var sqlStmt = "SELECT MAIL_ACCOUNT,MAIL_PASSWORD,MAIL_HOST,MAIL_PORT,WOS_MAIL FROM USRADMIN.SYS_MAIL";
|
| | |
|
| | | SqlStmt = "SELECT MAIL_ACCOUNT,MAIL_PASSWORD,MAIL_HOST,MAIL_PORT,WOS_MAIL FROM USRADMIN.SYS_MAIL";
|
| | | OracleCommand command = new OracleCommand(sqlStmt, conn);
|
| | | OracleDataReader reader = command.ExecuteReader();
|
| | |
|
| | | OracleCommand Command = new OracleCommand(SqlStmt, _Conn);
|
| | | OracleDataReader reader = Command.ExecuteReader();
|
| | | |
| | | try
|
| | | {
|
| | | if (reader.Read())
|
| | | {
|
| | | SMTP_IP = reader["MAIL_HOST"].ToString();
|
| | | SMTP_Port = Convert.ToInt32(reader["MAIL_PORT"].ToString());
|
| | | EMailAddr = reader["MAIL_ACCOUNT"].ToString();
|
| | | EMailPass = reader["MAIL_PASSWORD"].ToString();
|
| | | ToEMail = reader["CCS_MAIL"].ToString();
|
| | | _smtpIp = reader["MAIL_HOST"].ToString();
|
| | | _smtpPort = Convert.ToInt32(reader["MAIL_PORT"].ToString());
|
| | | _eMailAddr = reader["MAIL_ACCOUNT"].ToString();
|
| | | _eMailPass = reader["MAIL_PASSWORD"].ToString();
|
| | | _toEMail = reader["CCS_MAIL"].ToString();
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | |
| | | finally
|
| | | {
|
| | | reader.Close();
|
| | | Command.Dispose();
|
| | | command.Dispose();
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | }
|
| | | } |