using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using YARTE.UI.Buttons; using NetOffice; using Outlook = NetOffice.OutlookApi; using NetOffice.OutlookApi.Enums; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab; namespace FCM0000 { public partial class fSendMail : FCOMMON.fBase { public fSendMail() { InitializeComponent(); Properties.Settings.Default["gwcs"] = FCOMMON.info.CS; PredefinedButtonSets.SetupDefaultButtons(this.tbBody); this.dsMSSQL.MailData.TableNewRow += MailForm_TableNewRow; } void MailForm_TableNewRow(object sender, DataTableNewRowEventArgs e) { e.Row["gcode"] = FCOMMON.info.Login.gcode; e.Row["wuid"] = FCOMMON.info.Login.no; e.Row["wdate"] = DateTime.Now; e.Row["cate"] = "NR"; e.Row["pdate"] = DateTime.Now.ToShortDateString(); e.Row["fromlist"] = "gw@amkor.co.kr"; } private void fMailform_Load(object sender, EventArgs e) { EnsureVisibleAndUsableSize(); this.bs.AddNew(); //신규메일데이터생성 LoadNRData(); } void LoadNRData() { //자로에서 불러와서 그 값을 가져온다. DSMailTableAdapters.MailFormTableAdapter taMF = new DSMailTableAdapters.MailFormTableAdapter(); var data = taMF.GetByCate(FCOMMON.info.Login.gcode, "NR"); if (data != null && data.Rows.Count > 0) { var drForm = data.Rows[0] as DSMail.MailFormRow; this.tbSubject.Text = drForm.subject; this.tbBody.Html = drForm.body; this.tbTo.Text = drForm.tolist; //this.tbBCC.Text = drForm.bcc; //this.tbCC.Text = drForm.cc; } } private void mailFormBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); var drv = this.bs.Current as DataRowView; drv["subject"] = this.tbSubject.Text; drv["body"] = this.tbBody.Html; drv.EndEdit(); this.bs.EndEdit(); var cnt = this.tam.UpdateAll(this.dsMSSQL); MessageBox.Show($"{cnt}"); this.bs.AddNew(); tbTo.Text = FCOMMON.info.Login.email; } private void toolStripButton1_Click_1(object sender, EventArgs e) { var drv = this.bs.Current as DataRowView; if (drv == null) return; var dr = drv.Row as DSMail.MailFormRow; var tolist = new string[] { "Chikyun.kim@amkor.co.kr" }; //dr.tolist.Split(','); Outlook.Application outlookApplication = new Outlook.Application(); foreach (var to in tolist) { if (to.isEmpty()) continue; var newMail = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem; newMail.Display(); newMail.Subject = this.tbSubject.Text.Trim(); // dr.title; newMail.To = to; newMail.CC = tbCC.Text.Trim(); newMail.BCC = tbBCC.Text.Trim(); // newMail.BodyFormat = OlBodyFormat.olFormatHTML; newMail.HTMLBody = this.tbBody.Html .Replace("{USER}", FCOMMON.info.Login.nameK) .Replace("{EUSER}", FCOMMON.info.Login.nameE) .Replace("{EMAIL}", FCOMMON.info.Login.email) .Replace("%7BEMAIL%7D", FCOMMON.info.Login.email) .Replace("{HP}", FCOMMON.info.Login.hp) .Replace("{TEL}", FCOMMON.info.Login.tel) .Replace("{ITEM}", tbSubject.Text) + newMail.HTMLBody; } } private void toolStripButton1_Click(object sender, EventArgs e) { //direct send var list_from = "gw@amkor.co.kr"; var list_to = tbTo.Text; var subject = tbSubject.Text; var body = tbBody.Html; var list_bcc = tbBCC.Text; var list_cc = tbCC.Text; //전송을 해야 함 var mc = new System.Net.Mail.SmtpClient(FCOMMON.info.mailserver); var msg = new System.Net.Mail.MailMessage (list_from, list_to, subject, body); if (list_bcc != "") msg.Bcc.Add(list_bcc); if (list_cc != "") msg.CC.Add(list_cc); msg.IsBodyHtml = true; try { mc.Send(msg); MessageBox.Show("ok"); } catch (Exception eX) { MessageBox.Show(eX.Message); } } } }