MailAddress objFrom = new MailAddress("knreddy@gmail.com","reddy");
MailAddress objTo = new MailAddress("knreddy@gmail.com");
Now create a mail message, using from and to mail address objects:
MailMessage msgMail = new MailMessage(objFrom, objTo);
Let say, you want to send an email to multiple people then you’ll have to create a mail address collection object using MailAddressCollection class, and then add MailAddress objects in that collection.
MailAddressCollection objCCCollection = new MailAddressCollection();
MailAddress objCC = new MailAddress("cc email1");
objCCCollection.Add(objCC);
objCC = new MailAddress("cc email2");
objCCCollection.Add(objCC);
//Now, add this email collection address in your mail message object:
msgMail.CC.Add(objCCCollection);
//Similar is the case with BCC:
MailAddressCollection objBCCCollection = new MailAddressCollection();
MailAddress objBCC = new MailAddress("bcc email");
msgMail.Bcc.Add(objBCCCollection);
An email can be sent using two formats i.e. HTML or Text. You can specify this format as under:
msgMail.IsBodyHtml = true;
Now, set email subject and email body as under:
msgMail.Subject = "hi";
msgMail.Body = "hi";
An SMTP server is used to send an email, you an either use your own server settings or your web host’s smtp mail settings. You need to check your hosting details or ask your hosting service provider about your SMTP settings.
SmtpClient objSMTP = new SmtpClient();
Follwing statement will assign credentials to this smtp object. The credentials should be a valid email account on your mail server.
objSMTP.Credentials = new System.Net.NetworkCredential("youusername", "yourpassword");
Sepecify your smtp server’s host and port number, by default it is 25:
objSMTP.Host = "sarangan";
objSMTP.Port = 25;
Subscribe to:
Post Comments (Atom)
hi thanks for your information regarding mailing concept in asp.net
ReplyDelete