MainForm.cs
上传用户:linger1010
上传日期:2008-12-08
资源大小:561k
文件大小:2k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.WindowsMobile.PocketOutlook;
- namespace SendingEmail
- {
- public partial class MainForm : Form
- {
- OutlookSession m_outlookSession;
- public MainForm()
- {
- InitializeComponent();
- m_outlookSession = new OutlookSession();
- m_getAccounts();
- }
- private void m_getAccounts()
- {
- foreach (EmailAccount a in m_outlookSession.EmailAccounts)
- {
- m_cmbAccounts.Items.Add(a.Name);
- }
- m_cmbAccounts.SelectedIndex = 0;
- }
- private void m_mnuExit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void m_mnuSend_Click(object sender, EventArgs e)
- {
- try
- {
- // 构造Email消息对象
- EmailMessage msg = new EmailMessage();
- // 为Email消息设置属性
- msg.To.Add(new Recipient(m_txtTo.Text));
- msg.CC.Add(new Recipient(m_txtCc.Text));
- msg.Subject = m_txtSubject.Text;
- msg.BodyText = m_txtMessage.Text;
- // 选择一个可用的Email帐户,并发送消息
- EmailAccount a = m_outlookSession.EmailAccounts[m_cmbAccounts.SelectedIndex];
- a.Send(msg);
- // 向用户提示发送成功的信息
- MessageBox.Show(
- "Your email has been sent!",
- "Send",
- MessageBoxButtons.OK,
- MessageBoxIcon.Asterisk,
- MessageBoxDefaultButton.Button1);
- // 清空文本框,准备输入下一条消息
- m_txtTo.Text = String.Empty;
- m_txtCc.Text = String.Empty;
- m_txtSubject.Text = String.Empty;
- m_txtMessage.Text = String.Empty;
- }
- catch (Exception ex)
- {
- MessageBox.Show(
- String.Format("Error: {0}", ex.Message),
- "Send",
- MessageBoxButtons.OK,
- MessageBoxIcon.Hand,
- MessageBoxDefaultButton.Button1);
- }
- }
- }
- }