Thursday, July 16, 2009

Sending email through System.Net.Mail.Smtpmail in asp.net 3.5/2.0


For any web application or website the sending email is a necessity for newsletter, invitation or reset password for everything we have to sent a mail to the people. So we need to see how we can send mail. In 1.1 we are sending emails with System.Web.Mail.SmtpMail which is now obsolete. Now in asp.net 2.0 or higher version there is a namespace called System.Net.Mail.Smtpmail in asp.net 3.5. With this namespace we can easily write a code to send mail within couple of minutes.

If you want to sent a mail first thing you need is smtpserver. Smtpserver is a server which will route and send mail to particular system. To use smtpserver we need to configure some settings in web.config following is the setting for the web.config.

<system.net>

    <mailsettings>

       <smtp deliveryMethod="Network">

         <network host="stmp server address or ip"

           port="Smtp port" defaultCredentials="true"/>

        </smtp>     

    </mailsettings>

</system.net>


Here you need to set the all the smtp configuration. This will be used by the smptclient by default. Here is the code for sending email in asp.net 3.5

SmtpClient smtpClient = new SmtpClient();

MailMessage message = new MailMessage();

try

{

   MailAddress fromAddress = new MailAddress("[email protected]","Nameofsendingperson");

   message.From = fromAddress;//here you can set address

   message.To.Add("[email protected]");//here you can add multiple to

   message.Subject = "Feedback";//subject of email

   message.CC.Add("[email protected]");//ccing the same email to other email address

   message.Bcc.Add(new MailAddress("[email protected]"));//here you can add bcc address

   message.IsBodyHtml = false;//To determine email body is html or not

   message.Body =@"Plain or HTML Text";

   smtpClient.Send(message);

}

catch (Exception ex)

{

   //throw exception here you can write code to handle exception here

}


So from above simple code you can add send email to anybody
Adding Attachment to the email:If you want to attach some thing in the code then you need to write following code.

message.Attachments.Add(New System.Net.Mail.Attachment(Filename));


Here file name will the physical path along with the file name. You can attach multiple files with the mail.

Sending email with Authentication: If you want to sent a email with authentication then you have to write following code.

System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();

     //This object stores the authentication values

     System.Net.NetworkCredential basicCrenntial = 
          new System.Net.NetworkCredential("username", "password");

     mailClient.Host = "Host";

     mailClient.UseDefaultCredentials = false;

     mailClient.Credentials = basicCrenntial;

     mailClient.Send(message);



Happy Coding…
Share:
Monday, July 13, 2009

Google SMS Channel –Subscribe my post via SMS

Mobile has been very useful device since its launched. Now days we can not live without mobile. Think if you have your own sms channel and you can send message to your subscribers about your thought your blogs. It seems like a dream but now dream comes true. Google has launched new sms channel through which you can sent any thing to your subscribers. Now you guys can have my blog post via sms. I have created my channel at Google sms channel. You just need to subscribe that channel that’s it. You will have all my updates of blog on your mobile.

Here is the link for subscribing my blog post.

http://labs.google.co.in/smschannels/subscribe/DotNetJaps

Click this link and subscribe this channel and you will have all my blog updates on your mobile. Its free any one can create his/here channel. Go to http://labs.google.co.in/smschannels and try create new channel link and that’s it you are having your own sms channel.

GoogleLabs

Share:
Sunday, July 12, 2009

Wave.Google.com –A new communication tool.

Google wave is a new communication and sharing tool coming this year. With wave people can do lots of this things in a single browser like communication,videos,map link sharing, rich formatted text etc.

You can have a group chat and any participant can reply anywhere in message. edit content and add participant at any point any time.

You can also do lots of things like created gadgets thanks to wave api available on wave.Google.com.wave.Google.com is having key technologies like natural language processing, Real time conversation etc. Here is the some video for that.

Natural Language Processing:

Another one live collaborative editing.

If you want to play with wave google api then here is the link for that.

http://code.google.com/apis/wave/

And here is the Google developer preview video.

Happy surfing…

Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews