//送信ボタン private void button1_Click(object sender, EventArgs e) { Form_DispMail maildisp = new Form_DispMail(); mailTempleteDS maildt = new mailTempleteDS(); maildt.subject = m_templetename.Text; maildt.body = m_body.Text.Replace("\n", "\r\n"); maildisp.mailtempDS = maildt; maildisp.con = con; maildisp.loginDS = loginDS; //テンプレート表示 maildisp.Show(); }
//リストをダブルクリック private void m_mailTempleteList_DoubleClick(object sender, EventArgs e) { if (this.m_mailTempleteList.SelectedItems.Count > 0) { m_To_list.Clear(); m_Cc_list.Clear(); m_Bcc_list.Clear(); m_To_list.Columns.Add("アドレス名", 120); m_To_list.Columns.Add("アドレス", 120); m_To_list.Columns.Add("区分", 20); m_Cc_list.Columns.Add("アドレス名", 120); m_Cc_list.Columns.Add("アドレス", 120); m_Cc_list.Columns.Add("区分", 20); m_Bcc_list.Columns.Add("アドレス名", 120); m_Bcc_list.Columns.Add("アドレス", 120); m_Bcc_list.Columns.Add("区分", 20); ListView.SelectedIndexCollection item = m_mailTempleteList.SelectedIndices; mailTempleteDS maildt = new mailTempleteDS(); maildt.templateno = this.m_mailTempleteList.Items[item[0]].SubItems[0].Text; maildt.template_name = this.m_mailTempleteList.Items[item[0]].SubItems[1].Text; maildt.subject = this.m_mailTempleteList.Items[item[0]].SubItems[2].Text; maildt.body = this.m_mailTempleteList.Items[item[0]].SubItems[3].Text; maildt.account = this.m_mailTempleteList.Items[item[0]].SubItems[4].Text; maildt.attach1 = this.m_mailTempleteList.Items[item[0]].SubItems[5].Text; maildt.attach2 = this.m_mailTempleteList.Items[item[0]].SubItems[6].Text; maildt.attach3 = this.m_mailTempleteList.Items[item[0]].SubItems[7].Text; maildt.attach4 = this.m_mailTempleteList.Items[item[0]].SubItems[8].Text; maildt.attach5 = this.m_mailTempleteList.Items[item[0]].SubItems[9].Text; maildt.chk_date = this.m_mailTempleteList.Items[item[0]].SubItems[10].Text; maildt.chk_name_id = this.m_mailTempleteList.Items[item[0]].SubItems[11].Text; //アドレスを取得 Class_Detaget dg = new Class_Detaget(); mailsendaddressDSList = dg.getToCcBcc(maildt.templateno, con); DispMailtemplete(maildt); } }
//OutLookの下書きフォルダにメールを格納する。(デフォルトのアカウントに保存する private void CreateMailItem() { try { mailTempleteDS ds = new mailTempleteDS(); ds.subject = m_subject.Text; ds.body = m_body.Text; ds.account = m_account.Text; ds.attach1 = m_temp1.Text; ds.attach2 = m_temp2.Text; ds.attach3 = m_temp3.Text; ds.attach4 = m_temp4.Text; ds.attach5 = m_temp5.Text; string mailaddress; string name; //アドレス編集 for (int i = 0; i < this.m_To_list.Items.Count; i++) { name = this.m_To_list.Items[i].SubItems[0].Text; mailaddress = this.m_To_list.Items[i].SubItems[1].Text; ds.Toaddress += name + " <" + mailaddress + ">;"; } for (int i = 0; i < this.m_Cc_list.Items.Count; i++) { name = this.m_Cc_list.Items[i].SubItems[0].Text; mailaddress = this.m_Cc_list.Items[i].SubItems[1].Text; ds.CcAddress += name + " <" + mailaddress + ">;"; } for (int i = 0; i < this.m_Bcc_list.Items.Count; i++) { name = this.m_Bcc_list.Items[i].SubItems[0].Text; mailaddress = this.m_Bcc_list.Items[i].SubItems[1].Text; ds.BccAddress += name + " <" + mailaddress + ">;"; } //指定されたアカウントを設定する String smtpAddress = ""; smtpAddress = m_account.Text; var app = new Outlook.Application(); Outlook.Account account = null; if (smtpAddress != null && smtpAddress != "") { Outlook.Accounts accounts = app.Session.Accounts; foreach (Outlook.Account maccount in accounts) { // When the e-mail address matches, return the account. if (maccount.SmtpAddress == smtpAddress) { account = maccount; } } } // Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem; if (account != null) { //送信アカウントを設定 mail.SendUsingAccount = account; } mail.Subject = m_subject.Text; mail.To = ds.Toaddress; mail.CC = ds.CcAddress; mail.BCC = ds.BccAddress; //Outlook.AddressEntry currentUser = app.Session.CurrentUser.AddressEntry; mail.Body = m_body.Text; //添付ファイル // ファイルが存在しているかどうか確認する if (System.IO.File.Exists(ds.attach1)) { mail.Attachments.Add(ds.attach1); } if (System.IO.File.Exists(ds.attach2)) { mail.Attachments.Add(ds.attach2); } if (System.IO.File.Exists(ds.attach3)) { mail.Attachments.Add(ds.attach3); } if (System.IO.File.Exists(ds.attach4)) { mail.Attachments.Add(ds.attach4); } if (System.IO.File.Exists(ds.attach5)) { mail.Attachments.Add(ds.attach5); } //アドレス帳を参照する mail.Recipients.ResolveAll(); //下書きに保存 mail.Save(); //送信してしまう //mail.Send(); MessageBox.Show("OutLookに出力しました。"); } catch (Exception ex) { MessageBox.Show("OutLookに出力する際にエラーが発生しました。エラー:" + ex.Message, "メール出力"); } }
//表示 private void DispMailtemplete(mailTempleteDS maildt) { m_tempno.Text = maildt.templateno; m_templetename.Text = maildt.template_name; m_subject.Text = maildt.subject; m_body.Text = maildt.body; m_account.Text = maildt.account; m_update.Text = maildt.chk_date; m_updateOpe.Text = maildt.chk_name_id; m_temp1.Text = maildt.attach1; m_temp2.Text = maildt.attach2; m_temp3.Text = maildt.attach3; m_temp4.Text = maildt.attach4; m_temp5.Text = maildt.attach5; Dictionary <string, string> address = new Dictionary <string, string>(); List <String> toList = new List <String>(); List <String> CcList = new List <String>(); List <String> BccList = new List <String>(); //宛先の表示 foreach (mailsendaddressDS ms in mailsendaddressDSList) { MailaddressDS addressds = new MailaddressDS(); string tocc = ""; tocc = ms.toccbcc; if (tocc != "") { if (tocc == "To") { ListViewItem lvi; lvi = m_To_list.Items.Add(ms.addressname); lvi.SubItems.Add(ms.mailaddress); //1:オペレータ 2:カスタマ担当者 if (ms.kubun == "1") { lvi.SubItems.Add("オペレータ"); } //2:カスタマ担当者 else if (ms.kubun == "2") { lvi.SubItems.Add("担当者"); } //非表示項目 lvi.Tag = ms.addressno + "," + ms.kubun + "," + ms.opetantouno; } if (tocc == "Cc") { ListViewItem lvi; lvi = m_Cc_list.Items.Add(ms.addressname); lvi.SubItems.Add(ms.mailaddress); //1:オペレータ 2:カスタマ担当者 if (ms.kubun == "1") { lvi.SubItems.Add("オペレータ"); } //2:カスタマ担当者 else if (ms.kubun == "2") { lvi.SubItems.Add("担当者"); } //非表示項目 lvi.Tag = ms.addressno + "," + ms.kubun + "," + ms.opetantouno; } if (tocc == "Bcc") { ListViewItem lvi; lvi = m_Bcc_list.Items.Add(ms.addressname); lvi.SubItems.Add(ms.mailaddress); //1:オペレータ 2:カスタマ担当者 if (ms.kubun == "1") { lvi.SubItems.Add("オペレータ"); } //2:カスタマ担当者 else if (ms.kubun == "2") { lvi.SubItems.Add("担当者"); } //非表示項目 lvi.Tag = ms.addressno + "," + ms.kubun + "," + ms.opetantouno; } } } }