I have started work on a new personal project, ResumeSpammer. ResumeSpammer will do just what its name implies, spam my resume. Contact info of potential employers will be stored in a SQL Express database. For each employer, the application will populate my resume document (.doc) with their contact information and email it to them. There's a bit more to the project than that, but that's the just of it.
Today I wrote HacheyORG.ResumeSpammer.Logic.Resume, a class to handle populating and saving my resume with an employer's contact info. To interact with MS Word, I had to use its Primary Interop Assembly (PIA) It was my first time using Interop Assemblies, and it wasn't enjoyable in the least! I better get comfortable with interops, cause I'm sure I'll run into them again.
One hurdle I ran into was not being able to have one MS Word bookmark point to multiple locations in the document. This would have come in very handy for fields such as RecipientName, which appear multiple times in the cover letter. As a workaround, I gave each bookmark location a unique name (ie RecipitentName1, RecipientName2, etc.) and wrote a function that will detect if there are mutliple bookmarks and loop over them.
Yesterday I wrote HacheyORG.Lib.MailService, a class that utilizes System.Net.Mail to send emails with optional attachments through a SMTP server. In my case, I wanted to send emails through GMail's SMTP server. I had quite a bit of trouble figuring it out, so I'll post the code for reference. This snippet should work for Yahoo!Mail and HotMail as well, you will just need to figure out their servers' hostname and port.
using (MailMessage message = new MailMessage(from, to, subject, body))
{
message.IsBodyHtml = false;
SmtpClient mailClient = new SmtpClient();
mailClient.Host = "smtp.gmail.com";
mailClient.Port = 587;
mailClient.EnableSsl = true;
mailClient.Credentials = new System.Net.NetworkCredential(username, password);
mailClient.Send(message);
}