Click here to Skip to main content
12,450,347 members (43,262 online)
Click here to Skip to main content

Stats

137.8K views
1K downloads
106 bookmarked
Posted

Sending complex emails in .NET 1.1

, 15 Mar 2006
This article describes complex issues about sending emails in .NET 1.1 (such as using a SMTP server that requires authentication).
SampleSendMail
App.ico
bin
SampleSendMail.csproj.user
Utils
bin
Utils.csproj.user
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Utils;
using System.Web.Mail;

namespace SampleSendMail
{
	/// <summary>
	/// Summary description for SampleForm.
	/// </summary>
	public class SampleForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SampleForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new SampleForm());
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(72, 80);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(128, 23);
			this.button1.TabIndex = 0;
			this.button1.Text = "Send Sample Email";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(216, 80);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(224, 23);
			this.button2.TabIndex = 1;
			this.button2.Text = "Send Sample Email with Authentication";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// SampleForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(552, 182);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Name = "SampleForm";
			this.Text = "SampleForm";
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			EnhancedMailMessage.QuickSend("smtp.server.com", 
				"to.email@domain.com", 
				"from.email@domain.com",
				"Subject",
				"Body",
				MailFormat.Html);
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			EnhancedMailMessage msg = new EnhancedMailMessage();

			msg.From = "your.address@gmail.com";
			msg.FromName = "Your name";
			msg.To = "to.email@domain.com";
			msg.Subject = "Test email from gmail";
			msg.Body = "Gmail is great";

			msg.SMTPServerName = "smtp.gmail.com";
			msg.SMTPUserName = "your.address@gmail.com";
			msg.SMTPUserPassword = "yourpassword";
			msg.SMTPServerPort = 465;
			msg.SMTPSSL = true;

			msg.Send();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author


You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 16 Mar 2006
Article Copyright 2006 by FlorentinB
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid