Where did you copy that code from? It appears to have been intended for an Outlook add-in. Are you specifically trying to automate Outlook or do you just want to send an email because, if it's the latter, you should be using an SmtpClient object.