Sending email using c#

perfectpoint

Junior Member
Joined
Sep 21, 2010
Messages
197
Reaction score
94
I am using windows application i want to know how can I send email using windows application of c#, can anyone help me regarding this?
 
via which type of mail protocol? there are several options.

if you google, there are loads of answers.

start with the System.Net.Mail namespace.
 
lol its very easy ! bro search google u can find chilcat component to do all the web work for you !
 
check out the 'openpop' pop3 libraries they are free and open souce..
 
Here you go.

// create mail message object
MailMessage mail = new MailMessage();
mail.From = ""; // put the from address here
mail.To = ""; // put to address here
mail.Subject = ""; // put subject here
mail.Body = ""; // put body of email here
SmtpMail.SmtpServer = ""; // put smtp server you will use here
// and then send the mail
SmtpMail.Send(mail);
 
Here you go.

// create mail message object
MailMessage mail = new MailMessage();
mail.From = ""; // put the from address here
mail.To = ""; // put to address here
mail.Subject = ""; // put subject here
mail.Body = ""; // put body of email here
SmtpMail.SmtpServer = ""; // put smtp server you will use here
// and then send the mail
SmtpMail.Send(mail);


i don't believe you can assign the .To property of the MailMessage class directly to a string value.

if i recall correctly it has to either be passed to the constructor of the MailMessage when it is instantiated, or added using the .Add() method.

e.g.:

Code:
MailMessage mail = new MailMessage();
mail.To.Add(recip);
also, the .From and .ReplyTo properties are of the type MailAddress. i don't believe they can be assigned to a string either. probably depends on the version of the framework you're in, but in the last few implementations i have done, i have used the MailAddress class. you could probably also use a cast.

e.g.:

Code:
MailAddress mailAddress = new MailAddress("[email protected]");
mail.From = mailAddress;
mail.ReplyTo = mailAddress;
 
Back
Top