Sunday, July 12, 2009

I made a program in C# (Visual Studio 2005) and I was wondering if you can tell me how to make it e-mail me!?

I want it to e-mail me with what i put in 2 text boxes


For example if i put in first textbox the word blah and in the second on the word blahbluh, how do i get it to e-mail me with those two words !





Thank You

I made a program in C# (Visual Studio 2005) and I was wondering if you can tell me how to make it e-mail me!?
the internal help files will tell you. they aren't there foir decoration.
Reply:////////////////////////////////////////...


Example Code :


// Create a mailman object for sending email.


Chilkat.MailMan mailman = new Chilkat.MailMan();





// Any string argument automatically begins the 30-day trial.


mailman.UnlockComponent("30-day trial");





// Set the SMTP server hostname.


mailman.SmtpHost = "smtp.earthlink.net";





// Create a simple email.


Chilkat.Email email = new Chilkat.Email();





email.Body = "This is the body";


email.Subject = "This is the subject";


email.AddTo("Chilkat Support","support@chilkatsoft.com");


email.From = "Jack Johnson %26lt;jj@chilkatsoft.com%26gt;";





// Send mail.


bool success;


success = mailman.SendEmail(email);


if (success)


{


MessageBox.Show("Sent mail!");


}


else


{


MessageBox.Show(mailman.LastErrorText)...


}





//////////////////////////////////////...


This is a very simple example showing how to send a basic HTML email in C#.





// Create a mailman object for sending email.


Chilkat.MailMan mailman = new Chilkat.MailMan();





// Any string argument automatically begins the 30-day trial.


mailman.UnlockComponent("30-day trial");





// Set the SMTP server hostname.


mailman.SmtpHost = "smtp.earthlink.net";





// Create a simple HTML email.


Chilkat.Email email = new Chilkat.Email();





email.SetHtmlBody("%26lt;html%26gt;%26lt;body%26gt;%26lt;b%26gt;%26lt;fon... color='red' size='+1'%26gt;This is red bold text%26lt;/font%26gt;%26lt;/b%26gt;%26lt;/html%26gt;");


email.Subject = "This is a simple HTML email";


email.AddTo("Chilkat Support","support@chilkatsoft.com");


email.From = "Jack Johnson %26lt;jj@chilkatsoft.com%26gt;";





// Send mail.


bool success;


success = mailman.SendEmail(email);


if (success)


{


MessageBox.Show("Sent HTML mail!");


}


else


{


MessageBox.Show(mailman.LastErrorText)...


}





//////////////////////////////////////...


This example program shows how to send a multiplart/alternative email.





// Create a mailman object for sending email.


Chilkat.MailMan mailman = new Chilkat.MailMan();





// Any string argument automatically begins the 30-day trial.


mailman.UnlockComponent("30-day trial");





// Set the SMTP server host.


mailman.SmtpHost = "smtp.earthlink.net";





// Create a simple multipart/alternative email.


Chilkat.Email email = new Chilkat.Email();





email.Body = "This is the plain-text alternative";


email.AddHtmlAlternativeBody("%26lt;html%26gt;%26lt;b... color='red' size='+1'%26gt;This is the HTML alternative body%26lt;/font%26gt;%26lt;/b%26gt;%26lt;/html%26gt;");


email.Subject = "This is a simple multipart/alternative email";


email.AddTo("Chilkat Support","support@chilkatsoft.com");


email.From = "Buddahead %26lt;buddahead@chilkatsoft.com%26gt;";





// If you're curious, show the MIME text of the email to be sent..


MessageBox.Show(email.GetMime());





// Send email.


bool success;


success = mailman.SendEmail(email);


if (success)


{


MessageBox.Show("Sent HTML mail!");


}


else


{


MessageBox.Show(mailman.LastErrorText)...


}





//////////////////////////////////////...


This C# example program shows how to add a file attachment to an email and send it.





bool success;





// Create a mailman object for sending email.


Chilkat.MailMan mailman = new Chilkat.MailMan();





// Any string argument automatically begins the 30-day trial.


mailman.UnlockComponent("30-day trial");





// Set the SMTP server host.


mailman.SmtpHost = "smtp.earthlink.net";





// Create a simple email with a file attachment.


Chilkat.Email email = new Chilkat.Email();





// This email will have both a plain-text body and an HTML body.


email.Body = "This is the plain-text alternative";


email.AddHtmlAlternativeBody("%26lt;html%26gt;%26lt;b... color='red' size='+1'%26gt;This is bold red text.%26lt;/font%26gt;%26lt;/b%26gt;%26lt;/html%26gt;");


email.Subject = "This email has a file attachment.";


email.AddTo("Chilkat Support","support@chilkatsoft.com");


email.From = "Hello World %26lt;hello@chilkatsoft.com%26gt;";





// Add a file attachment.


string contentType;


// Returns the content-type of the attachment (determined by the file extension)


// This return value is for informational purposes only.


contentType = email.AddFileAttachment("dude.gif");


if (contentType == null)


{


MessageBox.Show(email.LastErrorText);


return;


}





// If you're curious, show the MIME text of the email to be sent..


MessageBox.Show(email.GetMime());





// Send email.


success = mailman.SendEmail(email);


if (success)


{


MessageBox.Show("Sent mail with attachment!");


}


else


{


MessageBox.Show(mailman.LastErrorText)...


}





//////////////////////////////////////...


C# source code showing how to add multiple CC recipients to an email.





bool success = false;





// Create a mailman object for sending email.


Chilkat.MailMan mailman = new Chilkat.MailMan();





// Any string argument automatically begins the 30-day trial.


mailman.UnlockComponent("30-day trial");





// Set the SMTP server.


mailman.SmtpHost = "smtp.earthlink.net";





// Create an email with multiple CC recipients.


Chilkat.Email email = new Chilkat.Email();





// Set the basic email stuff: body, subject, "from", "to"


email.Body = "This is the email body";


email.Subject = "This is the email subject";


email.AddTo("Chilkat Support","support@chilkatsoft.com");


email.From = "Programmer %26lt;programmer@chilkatsoft.com%26gt;";





// To add multiple CC recipients, you can call AddCC multiple times


// and/or call AddMultipleCC with a comma-separated list of email addresses.


// Either method can be called any number of times. Chilkat automatically


// removes duplicates.


email.AddCC("","sales@chilkatsoft.com"...


email.AddCC("Chilkat HR","hr@chilkatsof.com");


email.AddMultipleCC("Jack Frost %26lt;jfrost@chilkatsoft.com%26gt;, matt@chilkatsoft.com, Bob %26lt;bob@chilkatsoft.com%26gt;");





// If you are curious, look at the full MIME text of the email...


MessageBox.Show(email.GetMime());





success = mailman.SendEmail(email);


if (success)


{


MessageBox.Show("Sent CC mail!");


}


else


{


MessageBox.Show(mailman.LastErrorText)...


}








//////////////////////////////////////...


Creating a new Smtp instance :


Before creating a new Smtp instance, ensure that the Jscape.Email scope is defined in your using statements, and that the Jscape.Email.dll is referenced in your project. Refer to Getting Started in the Email Factory for .NET Help for more information about adding the Jscape.Email.dll reference to your projects.





Create a new Smtp instance providing the SMTP server hostname as an argument.:


Smtp mySmtp = new Smtp("hostname");





Subscribing to Smtp Events:


The Smtp instance MUST subscribe to the Smtp events prior to invoking the Connect() method to ensure that all data sent by the SMTP server is captured.The Smtp component may publish one or more events during the lifetime of an Smtp session. Any object that subscribes to events published by the Smtp component can receive and process the following events.


The ConnectedEvent is fired by the Smtp instance once a connection to the SMTP server has been established.


The DisconnectedEvent is fired by the Smtp instance once the connection to the SMTP server has been released.


The CommandSentEvent is fired by the Smtp instance for each command sent to the SMTP server.


The DataReceivedEvent is fired by the Smtp instance for each response received from the SMTP server.


The following example illustrates subscribing to the Smtp component events.





// Subscribe to events


mySmtp.ConnectedEvent += new Smtp.ConnectedEventHandler(OnConnected);


mySmtp.DisconnectedEvent += new Smtp.DisconnectedEventHandler(OnDisconne...


mySmtp.DataReceivedEvent += new Smtp.DataReceivedEventHandler(OnDataRece...


mySmtp.CommandSentEvent += new Smtp.CommandSentEventHandler(OnCommandSe...





Now you can create the event handler methods you previously defined when subscribing to the Smtp events.





public void OnConnected(object sender, SmtpConnectedEventArgs e) {


Console.WriteLine("Connected to {0}", e.Host);


}


public void OnDisconnected(object sender, SmtpDisconnectedEventArgs e) {


if (mySmtp.IsConnected()) {


mySmtp.Disconnect();


}


Console.WriteLine("Disconnected.");


}


public void OnDataReceived(object sender, SmtpDataReceivedEventArgs e) {


Console.WriteLine("Response: "+e.Response);


}


public void OnCommandSent(object sender, SmtpCommandSentEventArgs e) {


Console.WriteLine("Command: "+e.Command);


}





Establishing a connection:


Once an Smtp instance has been created and subscribed to the Smtp events you may establish a connection to the SMTP server by invoking the Connect() method.





mySmtp.Connect();





Creating an Email message:


To create an email message, construct a new EmailMessage instance passing the To: address and From: address to the constructor. You may also assign the To and From properties on the EmailMessage instance if you are using the default US-ASCII character set encoding. See the following section for more information about specifying message properties. If you are using another character set encoding, use the SetTo and SetFrom methods. Refer to the Email Factory for .NET Help for more information.





EmailMessage message = new EmailMessage("ToAddress", "FromAddress");





Defining addressing and other message properties





In addition to passing the To and From addresses to the EmailMessage constructor, you can specify the properties on the message instance. The EmailMessage class also has properties and methods for adding carbon-copy, blind-carbon-copy, and reply-to recipients, and message subject and priority.





Note: The To and From addresses are required properties.





EmailMessage message = new EmailMessage();


message.To = "ToAddress";


message.From = "FromAddress";


message.Cc = "CcAddress";


message.Bcc = "BccAddress";


message.ReplyTo = "ReplyToAddress";





message.Priority = "normal";


message.Subject = "This is a test subject";





Defining the message body:


You can set the message body to the contents of a file, a database query result, or a hand-coded message, as shown in the following example. Refer to the Email Factory for .NET Help for more information about defining the message body contents from a FileStream.





message.SetBody("This is a sample message");





Adding message attachments:


You can add one or more attachments to an email message by invoking the AddAttachment() method passing an Attachment instance as an argument. The attachment instance can be constructed by passing a file path as an argument.


Note: Due to the way that the message body is copied when adding attachments it is important that attachments be added only after the body of the message has been defined. Changing the Body, Content-Type, or Content-Transfer-Encoding of the message after attachments have been added may result in undesired effects.





Attachment att = new Attachment("c:\home\report.doc");


message.AddAttachment(att);





Sending an Email message:


To send a message through an established connection simply invoke the Send() method passing the message instance as an argument.





mySmtp.Send(message);





Releasing a connection:


To release an established connection simply invoke the Disconnect() method as follows:


mySmtp.Disconnect();


No comments:

Post a Comment