Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to send a email message in ASP.NET using C#. Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Send a email message in ASP.NET C#. 22-Aug-05
Category
ASP.NET
Language
C# All Versions
Views
189
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
			1   //This code shows how to send email in asp.net using C#.
2   using System;
3   using System.Drawing;
4   using System.Collections;
5   using System.ComponentModel;
6   using System.Windows.Forms;
7   using System.Data;
8   using System.Web.Mail;//don't forget to include this namespace
9   
10  namespace Emailtest
11  {
12  	/// <summary>
13  	/// Summary description for Form1.
14  	/// </summary>
15  	public class Form1 : System.Windows.Forms.form
16  	{
17  		private System.Windows.Forms.TextBox textTo;
18  		private System.Windows.Forms.TextBox textSub;
19  		private System.Windows.Forms.RichTextBox richText;
20  		private System.Windows.Forms.Button btnSend;
21  		private System.Windows.Forms.TextBox textFrom;
22  		/// <summary>
23  		/// Required designer variable.
24  		/// </summary>
25  		private System.ComponentModel.Container components = null;
26  
27  		public Form1()
28  		{
29  			//
30  			// Required for Windows Form Designer support
31  			//
32  			InitializeComponent();
33  
34  			//
35  		// TODO: Add any constructor code after InitializeComponent call
36  			//
37  		}
38  
39  		/// <summary>
40  		/// Clean up any resources being used.
41  		/// </summary>
42  		protected override void Dispose( bool disposing )
43  		{
44  			if( disposing )
45  			{
46  				if (components != null) 
47  				{
48  					components.Dispose();
49  				}
50  			}
51  			base.Dispose( disposing );
52  		}
53  
54  		/// <summary>
55  		/// The main entry point for the application.
56  		/// </summary>
57  		[STAThread]
58  		static void Main() 
59  		{
60  			Application.Run(new Form1());
61  		}
62  
63  	
64  
65  		private void btnSend_Click(object sender, System.EventArgs e)
66  		{
67  			try
68  			{
69  			//create mail message object
70  			MailMessage Mailer = new MailMessage();
71  			Mailer.From = this.textFrom.Text;
72  			Mailer.To = this.textTo.Text;
73  			Mailer.Subject = this.textSub.Text;
74  			Mailer.Body = this.richText.Text;
75  				
76  			//add attachment to send
77  		MailAttachment att = new MailAttachment(@"c:\mail\test.txt");
78  			Mailer.Attachments.Add(att);
79  				
80  			//set the type of format either HTML or Text
81                          Mailer.BodyFormat = MailFormat.Text;
82  				
83  			//the ip address of your SMTP server
84  		         SmtpMail.SmtpServer = "127.0.0.1";
85  			SmtpMail.Send(Mailer);					
86  
87  			}
88  			catch(Exception e1)
89  			{
90  				
91  MessageBox.Show(e1.Message,"Error!",MessageBoxButtons.OK,MessageBoxIcon.Error);
92  
93  			}
94  
95  		}
96  		}
97  	}



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC