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

代碼
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)程序打印或打開一個(gè)程序名或文件名</param>
/// <param name="lpParameters">如lpszFlie是可執(zhí)行文件,則這個(gè)字串包含傳遞給執(zhí)行程序的參數(shù)</param>
/// <param name="lpDirectory">想使用的完整路徑</param>
/// <param name="nShowCmd">定義了如何顯示啟動(dòng)程序的常數(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è)計(jì)器變量。
/// </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è)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內(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實(shí)現(xiàn)發(fā)送郵件的文章就介紹到這了,更多相關(guān)C# OutLokk發(fā)送郵件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
c# 實(shí)現(xiàn)網(wǎng)頁加載后將頁面截取為長圖片
這篇文章主要介紹了c# 實(shí)現(xiàn)網(wǎng)頁加載后將頁面截取為長圖片的方法,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下2021-01-01
利用TaskManager爬取2萬條代理IP實(shí)現(xiàn)自動(dòng)投票功能
話說某天心血來潮想到一個(gè)問題,朋友圈里面經(jīng)常有人發(fā)投票鏈接,讓幫忙給XX投票,以前呢會(huì)很自覺打開鏈接幫忙投一票。可是這種事做多了就會(huì)考慮能不能使用工具來進(jìn)行投票呢,身為一名程序猿決定研究解決這個(gè)問題。感興趣的朋友一起學(xué)習(xí)吧2015-09-09
使用C#程序驗(yàn)證系統(tǒng)登錄用戶與目錄權(quán)限
這篇文章主要介紹了使用C#程序驗(yàn)證系統(tǒng)登錄用戶與目錄權(quán)限,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12
Unity3D基于OnGUI實(shí)時(shí)顯示FPS
這篇文章主要介紹了Unity3D基于OnGUI實(shí)時(shí)顯示FPS,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
那些年,我還在學(xué)習(xí)C# 學(xué)習(xí)筆記
那些年學(xué)了ASP.NET后,才開始學(xué)習(xí)C#,說來也怪,怎么學(xué)了ASP.NET才來學(xué)習(xí)C#,其實(shí)沒有什么的2012-03-03

