C#調(diào)用OutLokk實現(xiàn)發(fā)送郵件
更新時間:2022年12月27日 09:11:49 作者:芝麻粒兒
這篇文章主要為大家詳細介紹了如何利用C#調(diào)用OutLokk實現(xiàn)發(fā)送郵件的功能,文中的示例代碼講解詳細,對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實踐過程
效果

代碼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 查找與指定文件關(guān)聯(lián)在一起的程序的文件名
/// <summary>
/// 查找與指定文件關(guān)聯(lián)在一起的程序的文件名
/// </summary>
/// <param name="hwnd">窗口句柄</param>
/// <param name="lpOperation">指定字串“open”來打開lpFlie文檔,或指定“Print”來打印它</param>
/// <param name="lpFile">想用關(guān)聯(lián)程序打印或打開一個程序名或文件名</param>
/// <param name="lpParameters">如lpszFlie是可執(zhí)行文件,則這個字串包含傳遞給執(zhí)行程序的參數(shù)</param>
/// <param name="lpDirectory">想使用的完整路徑</param>
/// <param name="nShowCmd">定義了如何顯示啟動程序的常數(shù)值</param>
/// <returns>非零表示成功,零表示失敗</returns>
[DllImport("shell32.dll", EntryPoint = "ShellExecuteA")]
public static extern int ShellExecute(
IntPtr hwnd,
String lpOperation,
String lpFile,
String lpParameters,
String lpDirectory,
int nShowCmd
);
#endregion
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
if (Regex.IsMatch(textBox1.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
ShellExecute(this.Handle, String.Empty, "mailto:" + textBox1.Text, String.Empty, String.Empty, 1);
else
{
MessageBox.Show("請輸入正確的郵箱格式");
textBox1.Text = string.Empty;
}
}
}
}
partial class Form1
{
/// <summary>
/// 必需的設(shè)計器變量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
/// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(128, 41);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(152, 23);
this.button1.TabIndex = 1;
this.button1.Text = "調(diào)用OutLook對其發(fā)送";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(77, 12);
this.label1.TabIndex = 1;
this.label1.Text = "郵件接收人:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(95, 12);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(185, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "mingrisoft@mingrisoft.com";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 74);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "調(diào)用OutLook發(fā)送郵件";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
}
到此這篇關(guān)于C#調(diào)用OutLokk實現(xiàn)發(fā)送郵件的文章就介紹到這了,更多相關(guān)C# OutLokk發(fā)送郵件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于C#實現(xiàn)的多生產(chǎn)者多消費者同步問題實例
這篇文章主要介紹了基于C#實現(xiàn)的多生產(chǎn)者多消費者同步問題,包括了加鎖與釋放鎖,以及對應(yīng)臨界資源的訪問。是比較實用的技巧,需要的朋友可以參考下2014-09-09

