close

        /// <summary>
        /// 用SMTP發送email
        /// </summary>
        /// <param name="to">收件者</param>
        /// <param name="cc">cc</param>
        /// <param name="attfile">附件檔案path</param>
        /// <param name="subject">主題</param>
        /// <param name="body">內文</param>
        protected bool bspg_SendMail(string to, StringCollection cc, StringCollection attfile, string subject, string body)
        {
            bool rc = true;
         
            try
            {


                MailAddress ma_From = new MailAddress("abc@hinet.net.net", "系統");
                MailAddress ma_To = new MailAddress(to, to.Split('@')[0].ToString());
                MailMessage message = new MailMessage(ma_From, ma_To);

                MailAddressCollection mailcc = new MailAddressCollection();
                if (cc.Count > 0) //CC
                {
                    foreach (string txt in cc)
                    {
                          MailAddress scc = new MailAddress(txt, txt.Split('@')[0].ToString()); //不給DISPLAY NAME 經測試 CC 會收不到
                          message.CC.Add(scc);
                    }

                }

                if (attfile.Count > 0) //附件
                {
                    foreach (string str in attfile)
                    {
                        if (File.Exists(str) == true)
                            message.Attachments.Add(new Attachment(str));
                        else
                        {
                        
                            return false;
                        }
                    }
                }

                message.From = ma_From;
                message.To.Add( ma_To);
                message.Subject =  subject;
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.Body = body;
                message.IsBodyHtml = false;


                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.UseDefaultCredentials = false;
                client.Host = "192.168.1.100";
                client.Send(message);
            }
            catch (Exception )
            {
                rc = false;
            }
            return rc;
        }

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 11 的頭像
    11

    冠霖的部落格

    11 發表在 痞客邦 留言(0) 人氣()