Nowadays, you can't publish an email address anywhere without receiving a bunch of spam immediately after. Those spam web crawlers just search in every site looking for everything and anything that resembles an email address.
I very often see people use different variations of writing their email like "myname at mydomain.com" or "myname at mydomain dot com".
I don't think this covers it anymore...
The best way, in my opinion, is to create an image of the email address instead of writing it. (That's what Facebook does as well.)
I started working on a user based site, and the users' emails will be displayed throughout the site. So I created a class that will dynamically generate email address images for me so my precious users won't be so vulnerable to all the spam out there.
Here it is:
private int _emailFontSize = 8;
private string _emailFontFamily = "Verdana";
private Brush _emailBackgroundColor = Brushes.White;
private Brush _emailFontColor = Brushes.Navy;
public void CreateEmailImage(string email)
Font myFont = new Font(_emailFontFamily, _emailFontSize);
Bitmap emailImage = new Bitmap((int)(myFont.SizeInPoints * email.Length),
Graphics imgGraphics = Graphics.FromImage((Image)emailImage);
new Rectangle(new Point(0, 0), emailImage.Size));
imgGraphics.DrawString(email, myFont, _emailFontColor, new PointF(0, 0));
SizeF stringSize = imgGraphics.MeasureString(email, myFont);
Bitmap finalImage = CropImage(emailImage,
new Rectangle(new Point(0, 0), new Size((int)stringSize.Width,
finalImage.Save(email + ".gif", ImageFormat.Gif);
private Bitmap CropImage(Image imgCrop, Rectangle cropArea)
Bitmap bmpImage = new Bitmap(cropArea.Width, cropArea.Height - 1);
Graphics bmpG = Graphics.FromImage(bmpImage);
bmpG.DrawImage(imgCrop, new Point(0, 0));
I will probably make some changes before using this on my site:
- I don't think it's smart to give the file the name of the actual email address. I'll probably generate some unique ID but built from the users name.
- I haven't decided yet if I want the image to be a link to contact the user. If so, then I must create a unique id for each user, and have the link lead to that page with the unique id so I can identify the user being contacted.
- I'll probably add a simple caching mechanism to this, hence create a folder to store all the images, and then check if it exists before creating a new one each time.