Form1.cs
资源名称:yjal.rar [点击查看]
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:2k
源码类别:
Email客户端
开发平台:
Visual C++
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Reflection;
- using Outlook;
- namespace OutLookDemo
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btn发送Email_Click(object sender, EventArgs e)
- {
- Outlook._Application oApp = new Outlook.Application();
- Outlook.NameSpace oNameSpace = oApp.GetNamespace("MAPI");
- bool html = false;
- try
- {
- oNameSpace.Logon(Missing.Value, Missing.Value, true, true);
- Outlook.MAPIFolder oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
- Outlook.ApplicationClass a = new Outlook.ApplicationClass();
- Outlook.MailItem tt;
- tt = (Outlook.MailItem)a.CreateItem(OlItemType.olMailItem);
- tt.To = txt目标地址.Text;
- tt.CC = "";
- tt.Subject = txt标题.Text;
- if (html)
- {
- tt.HTMLBody = txt内容.Text;
- }
- else
- {
- tt.Body = txt内容.Text;
- }
- tt.SaveSentMessageFolder = oOutboxFolder;
- tt.Attachments.Add(txt附件.Text, Missing.Value, Missing.Value, Missing.Value);
- tt.Display(null);
- }
- finally
- {
- oNameSpace.Logoff();
- }
- }
- private void btn附件_Click(object sender, EventArgs e)
- {
- DialogResult dr=openFileDialog1.ShowDialog();
- if (dr == DialogResult.OK)
- {
- this.txt附件.Text = openFileDialog1.FileName;
- }
- }
- }
- }