Sending Email using ASP.NET

by Mohit Bhardwaj 24. March 2009 02:01

Last night I was thinking to write a small post about sending emails using .NET. Then I thought of using GMAIL smtp account to send email. So here is the code.

using System;
using System.Net;
using System.Net.Mail;

/// <summary>
/// Email Sending Class for GMAIL account.
/// </summary>

public class Emails
{
public Emails()
{
//
// TODO: Add constructor logic here
//
}

 

public string sendmail(string body)
{
try
{
MailMessage mail=
new MailMessage();
mail.To.Add(new MailAddress("xxxx@gmail.com"));
mail.From=
new MailAddress("yyyy@gmail.com");
mail.Body=body;
SmtpClient smtp=
new SmtpClient("smtp.gmail.com",587);
smtp.Credentials=new NetworkCredential("yyyy@gmail.com", "#&&$$%#%"); // This is where you have to specify account properties of the email account you are using to send email. yyyy@gmail.com is the userid and #&&$$%#% is the password.
smtp.EnableSsl=true;
smtp.Send(mail);
return "Success";
}
catch(Exception ex)
{
return "Failed";
}
}
 

Now from here you can call this class and send email. I have used the static emails here but you can make it change accordingly to use it as dynamically. You will need to add more paramaters like "body" in calling this function.

Thanks.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Beginners

Series for Beginner's - Creating new project

by Mohit Bhardwaj 18. March 2009 02:16

Whenever someone have to work on something in Visual Studio, he have to create a project to easily manage the code and the relative information about it. Visual Studio provides many different types of solutions but you need to choose the best suitable project or solution type. For creating an ASP.NET Project, you need to so following:

  1. Open Visual Studio 2005 or 2008, whatever system installed on your PC.
  2. In the left hand side of the Start Page, you can see Recent Projects.
  3. Below that in the same area, you can find "Create Website" link.
  4. IF, by some chance you can not find "Create Website", then go to File->New->Website.
  5. There you can find the different solutions related to ASP.NET.
  6. Choose the best that fits your needs, I mean if you want to create web services first then choose web services solution.

HINT: Personally I feel, whatever solution you choose, In the location dropdown, always choose HTTP, instead of FTP or File System and specify the path as http://localhost/ProjectName for a simple reason that, if you somehow migrate to different environment like you move from XP to Vista, like I did, I didn't have to worry about changing the settings for the projects and solutions, because, FileSystem uses an ASP.NET Virtual Server to run your project, and that server's PORT Number is configured automatically when you install .Net Framework. So better to choose localhost, do all the programming and then if you have to move to differenr OS, you just need to take copy of your localhost folder, I mean, wwwroot folder under, C:\inetpub.

Moreover, the solutions that you create always saved in your My Document->Visual Studio 2005->Projects, so make sure that you copy that too, before moving to the new OS.

AND ALWAYS, BACK UP THESE 2 FOLDERS.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Beginners

New Series

by Mohit Bhardwaj 13. March 2009 02:16

I would like to use this as a tool to spread the knowledge I have while working on ASP.NET. For starters, I will be posting a series for beginners.

It will help those young developers, who needs a professional approach towards development. I will call it as a "Series For Beginners". From now on, I will post related topics about the starting the website without any hush-mush for beginners, so that they can understand the concept easily.

Hope You all will like it.Smile

Currently rated 2.5 by 4 people

  • Currently 2.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Beginners

First Blog, First Entry

by Mohit Bhardwaj 12. March 2009 02:55

Hello to all,

This is my first blog entry ever and I am very much excited about this. So, please spend some time on my blog and see if you like something.

I hope you won't be disappointed.

Thanks.

Mohit Bhardwaj.

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

No Category

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About Me

Hi, I am Mohit Bhardwaj, living in New Delhi, India. I am an Independent software developer for Microsoft Technologies.

Hope you will like my posts here on this blog.

LinkedIn

Page List

    Calendar

    <<  March 2010  >>
    MoTuWeThFrSaSu
    22232425262728
    1234567
    891011121314
    15161718192021
    22232425262728
    2930311234

    View posts in large calendar