You are currently browsing the monthly archive for February 2011.

Sending emails through ASP.Net2.0  is very easy. Just a few lines of code. But when u get an error you will be surprised.  So before you write up the few lines of code you have to do the following.

Configure IIS for sending emails. Its simple not a big deal. Check if SMPT is already installed. If not installed than go to Add Remove Windows Components and double click IIS. Click SMTP. Install it and restart your system.  Now your local web server is ready for sending emails. The next thing is the coding part.

Add this line of code to the top of the page.

using System.Net.Mail;

To send an email you need the following parts of an email.

From (address who is sending the email)

To (to whom the emails is being sent)

Subject  (subject of the email)

Body (body text of the email)

Write the following code


string strFrom, strTo, strSubject, strBody;

strFrom = "sender@gmail.com";

strTo = "rece<a href="mailto:receiver@gmail.com">iver@gmail.com</a>";

strSubject = "Test Email";

strBody = "You have a test email.";

MailMessage eProEmail = new MailMessage(strFrom, strTo, strSubject, strBody);

SmtpClient emailClient = new SmtpClient("localhost");

emailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

emailClient.Send(eProEmail);

emailClient.Timeout = 500;

Run the code and check your email. I hope you will not encounter those errors saying “Mailbox not found” etc etc.

Advertisements

Before I can proceed with this tutorial I assume that the reader has already developed a report in crystal and has loaded it in crystal report viewer control. Running the website and the report page prompts the user with something like this.

Crystalreports Login Prompt

Crystalreports Login Prompt

Now we don’t want to give login information every time we try to run this report.  Its annoying . so what we need to do is to do something with the help of which we can get our report perfectly without this stupid prompt. To solve this problem we will provide the login information programmatically so that our report page don’t prompt us for it. To solve the problem I have done the following. Add the following code to the top of the report page.


using CrystalDecisions;

using CrystalDecisions.CrystalReports;

usingCrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

Now in the Page_Load()  event write the following code. Or we can write this code in any other function and call it when we want to provide the login information.

 

Now in the Page_Load()  event write the following code. Or we can write this code in any other function and call it when we want to provide the login information.


ReportDocument rpt = new ReportDocument();

rpt.Load(Server.MapPath("myReport.rpt"));

rpt.SetDatabaseLogon("myUserLogin", "mypassword", @"Server", "Database");

CrystalReportViewer1.ReportSource = rpt;

Save the page and run the report. This time it will not prompt for the stupid logon information. If some one wants a very basic article on how to create a report and how to call it in asp.net. plz leave your comments . I will write a basic tutorial for creating a crystal report and calling it from asp.net.

Note:- Plz  leave ur comments if this article was helpful.

Thanks.

 

Blog Stats

  • 329,708 hits

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 233 other followers

%d bloggers like this: