Thursday, March 11, 2010

CSS support in email clients

Today my coworker was struggling with the background image not being displayed properly on her Apple email client while doing a test email blast. She came over to me to ask over for help and I said, "Aah.. Dont worry, will be done in a minute", not knowing what was getting unfolded.

I soon figured there was no way to edit HTML or enter any HTML Tags in the outbound email. So I created a ASP.NET form with 2 input parameters; one for the email and the second one for the HTML. Picked up the custom Method from the library for sending the mail. And did the test Blast. Hmm, outlook made the image completely disappear. "Thats strange!", I said. After a lot of tweaks and several email blasts, I thought maybe now its time to do some research.

And then I got this neat table explaining everything:

Makes sense now. Darn! Should have looked into this earlier!

As for my co-worker, she now has to end up shrinking the image to accommodate the content side by side.

Lesson Learnt: Text cannot be over the image in the HTML Emails; forget the z-index's too.

Tuesday, March 2, 2010

FTP File to the Remote Server with ASP.NET

I came across issues where I wasnt able to ftp files on the remove FTP Server programatically. Following were some of the issues:

File was not created on the server
File was created but was not accessible
File was created but was not readable (encoded)

Here's the code that takes care of that:

FtpWebRequest ftpFile;
//Access the file which has to be uploaded
FileInfo fileInf = new FileInfo(Server.MapPath("~/filename.txt"));

ftpFile = (FtpWebRequest)WebRequest.Create("" + fileInf.Name);
ftpFile.Credentials = new NetworkCredential("username", "password");
//By default the connection is kept alive. Close the connection after the upload is done
ftpFile.KeepAlive = false;
ftpFile.Method = WebRequestMethods.Ftp.UploadFile;

//By default, Binary is true. If its true, the txt file becomes unreadable
ftpFile.UseBinary = false;
ftpFile.ContentLength = fileInf.Length;

Byte[] buff = new Byte[fileInf.Length];
int contentLen;
FileStream fs = fileInf.OpenRead();
Stream strm = ftpFile.GetRequestStream();
contentLen = fs.Read(buff, 0, buff.Length);
while (contentLen != 0)
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buff.Length);

ftpFile = null;