22 September 2008

Send Spam-free Email using ASP.NET

Sorry, the previous blog contains a class which has been deprecated. Please use the namespace System.Net.Mail instead of System.Web.Mail;

Moreover, mails sent in previous way were being marked as spam in GMail. Use a real mail server to reduce the probability of being spam. Here Google mail server has been used along with GMail account and password.

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";

MailMessage mail = new MailMessage("from@mail.com", "to@mail.com", "Subject", "Body");
smtp.Credentials = new System.Net.NetworkCredential("user@gmail.com", "password");
smtp.EnableSsl = true;


  1. ‘from’ address will not work, rather "user@gmail.com" will be the sender.
  2. It is not assured that mail will not be marked as spam.

Send Email using ASP.NET

In ASP.NET (using C#), it is very easy to send email. You need to include the namespace 'System.Web.Mail'. The rest is as follows-

MailMessage mailMsg = new MailMessage();
mailMsg.To = "ToSomeone@mail.com";
mailMsg.From = "FromSomeone@mail.com";
mailMsg.Subject = "subject of mail";
mailMsg.Body = "body of mail";


Sending attachment is also simple.

MailAttachment attachment = new MailAttachment("FilePath");

Note: The FilePath is the path in Server, not in client. So if you want to send attachment, first save the file in server temporarily, send mail and then delete the temporary file.

21 September 2008

How to upload file using ASP.NET in C#


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadFile.aspx.cs" Inherits="UploadFile" %>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Pagetitle>

<form id="form1" runat="server">
<input id="FileChooser" type="file" runat="server" />
<asp:Button ID="ButtonUpload" runat="server" Text="Upload" OnClick="ButtonUpload_Click" /><br />
<br />
<asp:Label ID="LabelStatus" runat="server" Width="36px">asp:Label>div>


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UploadFile : System.Web.UI.Page
private string uploadDirectory = @"D:\Testing projects\FileUpload\UploadedFiles";

protected void ButtonUpload_Click(object sender, EventArgs e)
if (this.FileChooser.PostedFile.ContentLength == 0)
this.LabelStatus.Text = "Can\'t upload zero length file.";
string fileName = this.getFileNameFromPath(this.FileChooser.PostedFile.FileName);
this.FileChooser.PostedFile.SaveAs(this.uploadDirectory + "\\"+ fileName);
this.LabelStatus.Text = "Uploaded to " + this.uploadDirectory;

private string getFileNameFromPath(string path)
int i = path.LastIndexOf('\\');
if (i == path.Length-1)
return null;
if (i < 0)
return path;
return path.Substring(i + 1);

14 September 2008

HTTrack : Website Copier

Wanna download all pages inside a website? Wanna download tutorial like sites where there are lots of pages inside a directory? Then you can use HTTrack. I found it extremely useful.

LateX: Download Link for Style files (*.sty)

While I was working on other's LateX file (*.tex), I found that some style files (*.sty) are missing. Then after googling, I found a useful link for downloading style files.

for example, if you look for fancyhdr.sty type the following url in browser.


Note: Look at the url, the name of the style file stays at the end.


© 2007 t!ps n tr!cks: September 2008

Template unik dari rohman

---[[ Skip to top ]]---