C#調用OutLokk實現發(fā)送郵件
更新時間:2022年12月27日 09:11:49 作者:芝麻粒兒
這篇文章主要為大家詳細介紹了如何利用C#調用OutLokk實現發(fā)送郵件的功能,文中的示例代碼講解詳細,對我們學習C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實踐過程
效果
代碼
public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region 查找與指定文件關聯在一起的程序的文件名 /// <summary> /// 查找與指定文件關聯在一起的程序的文件名 /// </summary> /// <param name="hwnd">窗口句柄</param> /// <param name="lpOperation">指定字串“open”來打開lpFlie文檔,或指定“Print”來打印它</param> /// <param name="lpFile">想用關聯程序打印或打開一個程序名或文件名</param> /// <param name="lpParameters">如lpszFlie是可執(zhí)行文件,則這個字串包含傳遞給執(zhí)行程序的參數</param> /// <param name="lpDirectory">想使用的完整路徑</param> /// <param name="nShowCmd">定義了如何顯示啟動程序的常數值</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> /// 必需的設計器變量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的資源。 /// </summary> /// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗體設計器生成的代碼 /// <summary> /// 設計器支持所需的方法 - 不要 /// 使用代碼編輯器修改此方法的內容。 /// </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 = "調用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 = "調用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; }
到此這篇關于C#調用OutLokk實現發(fā)送郵件的文章就介紹到這了,更多相關C# OutLokk發(fā)送郵件內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
利用TaskManager爬取2萬條代理IP實現自動投票功能
話說某天心血來潮想到一個問題,朋友圈里面經常有人發(fā)投票鏈接,讓幫忙給XX投票,以前呢會很自覺打開鏈接幫忙投一票??墒沁@種事做多了就會考慮能不能使用工具來進行投票呢,身為一名程序猿決定研究解決這個問題。感興趣的朋友一起學習吧2015-09-09