| Using system; Using system. drawing; Using system. collections; Using system. componentmodel; Using system. Windows. forms; Using system. Data; Using system. Web; Using system. Web. mail; // The namespace used in the import program Public class form1: Form { Private Label label1; Private Label label2; Private Label label3; Private button sendbutton; Private button exitbutton; Private textbox fromtextbox; Private textbox totextbox; Private textbox subjecttextbox; Private textbox messagetextbox; Private textbox cctextbox; Private Label cclabel; Private textbox bcctextbox; Private Label label4; Private Label label5; Private button browsebutton; Private openfiledialog openfiledialog1; Private textbox attachmenttextbox; Private system. componentmodel. Container components = NULL; Public form1 () { Initializecomponent (); } // Clear all resources used in the program Protected override void dispose (bool disposing) { If (disposing) { If (components! = NULL) { Components. Dispose (); } } Base. Dispose (disposing ); } Private void initializecomponent () { Messagetextbox = new Textbox (); Totextbox = new Textbox (); Sendbutton = new button (); Exitbutton = new button (); Fromtextbox = new Textbox (); Label1 = new label (); Subjecttextbox = new Textbox (); Label2 = new label (); Label3 = new label (); Cctextbox = new Textbox (); Cclabel = new label (); Bcctextbox = new Textbox (); Label4 = new label (); Label5 = new label (); Attachmenttextbox = new Textbox (); Browsebutton = new button (); Openfiledialog1 = new openfiledialog (); Fromtextbox. Location = new system. Drawing. Point (96, 16 ); Fromtextbox. Name = "fromtextbox "; Fromtextbox. size = new system. Drawing. Size (240, 20 ); Fromtextbox. tabindex = 0; Fromtextbox. Text = ""; Totextbox. Location = new system. Drawing. Point (96, 53 ); Totextbox. Name = "totextbox "; Totextbox. size = new system. Drawing. Size (240, 20 ); Totextbox. Text = ""; Totextbox. tabindex = 1; Cctextbox. Location = new system. Drawing. Point (96, 88 ); Cctextbox. Name = "cctextbox "; Cctextbox. size = new system. Drawing. Size (240, 20 ); Cctextbox. tabindex = 2; Cctextbox. Text = ""; Bcctextbox. Location = new system. Drawing. Point (96,120 ); Bcctextbox. Name = "bcctextbox "; Bcctextbox. size = new system. Drawing. Size (240, 20 ); Bcctextbox. tabindex = 3; Bcctextbox. Text = ""; Subjecttextbox. Location = new system. Drawing. Point (96,152 ); Subjecttextbox. Name = "subjecttextbox "; Subjecttextbox. size = new system. Drawing. Size (240, 20 ); Subjecttextbox. tabindex = 4; Subjecttextbox. Text = ""; Attachmenttextbox. Location = new system. Drawing. Point (96,184 ); Attachmenttextbox. Name = "attachmenttextbox "; Attachmenttextbox. size = new system. Drawing. Size (168, 20 ); Attachmenttextbox. tabindex = 5; Attachmenttextbox. Text = ""; Messagetextbox. Location = new system. Drawing. Point (8,216 ); Messagetextbox. multiline = true; Messagetextbox. Name = "messagetextbox "; Messagetextbox. size = new system. Drawing. Size (320,152 ); Messagetextbox. Text = ""; Messagetextbox. tabindex = 6; Browsebutton. Location = new system. Drawing. Point (280,184 ); Browsebutton. Name = "browsebutton "; Browsebutton. size = new system. Drawing. Size (56, 24 ); Browsebutton. Text = "Browse Files "; Browsebutton. tabindex = 7; Browsebutton. Click + = new system. eventhandler (browsebutton_click ); Sendutton. Location = new system. Drawing. Point (64,380 ); Sendbutton. Name = "sendbutton "; Sendbutton. size = new system. Drawing. Size (72, 24 ); Sendbutton. Text = "Send email "; Sendbutton. tabindex = 8; Sendbutton. Click + = new system. eventhandler (sendbutton_click ); Exitbutton. Location = new system. Drawing. Point (200,380 ); Exitbutton. Name = "exitbutton "; Exitbutton. size = new system. Drawing. Size (72, 24 ); Exitbutton. Text = "Exit program "; Exitbutton. tabindex = 9; Exitbutton. Click + = new system. eventhandler (exitbutton_click ); Label1.font = new system. Drawing. Font ("", 9f ); Label1.location = new system. Drawing. Point (48, 16 ); Label1.name = "label1 "; Label1.size = new system. Drawing. Size (48, 16 ); Label1.text = "Sender :"; Label2.font = new system. Drawing. Font ("", 9f ); Label2.location = new system. Drawing. Point (48, 53 ); Label2.name = "label2 "; Label2.size = new system. Drawing. Size (48, 16 ); Label2.text = "Recipient :"; Label3.font = new system. Drawing. Font ("", 9f ); Label3.location = new system. Drawing. Point (48,152 ); Label3.name = "label3 "; Label3.size = new system. Drawing. Size (48, 16 ); Label3.text = "Subject :"; Cclabel. font = new system. Drawing. Font ("", 9f ); Cclabel. Location = new system. Drawing. Point (48, 88 ); Cclabel. Name = "cclabel "; Cclabel. size = new system. Drawing. Size (48, 16 ); Cclabel. Text = "cc :"; Label4.font = new system. Drawing. Font ("", 9f ); Label4.location = new system. Drawing. Point (48,120 ); Label4.name = "label4 "; Label4.size = new system. Drawing. Size (48, 16 ); Label4.text = "BCC :"; Label5.font = new system. Drawing. Font ("", 9f ); Label5.location = new system. Drawing. Point (48,184 ); Label5.name = "label5 "; Label5.size = new system. Drawing. Size (48, 16 ); Label5.text = "attachment :"; Openfiledialog1.title = "select a file as an attachment to the email :"; This. autoscalebasesize = new system. Drawing. Size (5, 13 ); This. clientsize = new system. Drawing. Size (344,413 ); This. Controls. Add (browsebutton ); This. Controls. Add (attachmenttextbox ); This. Controls. Add (label5 ); This. Controls. Add (label4 ); This. Controls. Add (bcctextbox ); This. Controls. Add (cclabel ); This. Controls. Add (cctextbox ); This. Controls. Add (exitbutton ); This. Controls. Add (sendbutton ); This. Controls. Add (label3 ); This. Controls. Add (label2 ); This. Controls. Add (label1 ); This. Controls. Add (subjecttextbox ); This. Controls. Add (totextbox ); This. Controls. Add (fromtextbox ); This. Controls. Add (messagetextbox ); This. Name = "form1 "; This. Text = "Use Visual C # As the mail sending software! "; This. resumelayout (false ); } Static void main () { Application. Run (New form1 ()); } Private void sendbutton_click (Object sender, system. eventargs E) { Try { Mailmessage amessage = new mailmessage (); // Create a new mailmessage object Amessage. From = fromtextbox. text; // Define the sender address. If there are multiple users, separate them with commas (,). Amessage. To = totextbox. text; // Define the recipient address. If there are multiple recipients, separate them with commas (,). Amessage. Cc = cctextbox. text; // Defines the CC address. If there are multiple recipients, separate them with commas (,). Amessage. bcc = bcctextbox. text; // Defines the hidden recipient address. If there are multiple recipients, separate them with commas (,). Amessage. Subject = subjecttextbox. text; // Define the subject of the email Amessage. Body = messagetextbox. text; // Define the mail content If (attachmenttextbox. Text. length> 0) Amessage. attachments. Add (New mailattachment (attachmenttextbox. Text, mailencoding. base64 )); // Add an attachment to the email Smtpmail. Send (amessage ); // Send an email MessageBox. Show ("email has been sent to->" + totextbox. Text ); } Catch (exception ex) { MessageBox. Show (ex. Message. tostring ()); } } Private void exitbutton_click (Object sender, system. eventargs E) { Application. Exit (); } Private void browsebutton_click (Object sender, system. eventargs E) { If (openfiledialog1.showdialog () = dialogresult. OK) { Attachmenttextbox. Text = openfiledialog1.filename; }} } |