1
votes

I am trying to send an email from a client PC (i.e. Windows) with an attachment and have the attachment saved to a local folder on the same client PC. I have looked at a couple of alternatives, such as MailDrop (email to dropbox) and Outlook 2003 Interop library - but want to make sure I am implementing this the best way.

Does anyone have any different ideas on a simple/elegant solution?

1

1 Answers

0
votes

As long as you know Outlook will be installed on all the clients the Outlook solution works very well. You can create a file and save it, then in your outlook interop you just attach and send. You didn't specify what tools you are using but here's the basic email creation method I use for Outlook in C# (Where OutlookSetup.OutlookApp is just a static method that returns the currently open instance of the Outlook application or creates a new one if Outlook isn't open). Otherwise there are several examples here on SO of using SmtpClient to achieve similar ends.

public EmailMessage(EmailInfo emailInfo, string filenameToAttach=null)
{
    Message = OutlookSetup.OutlookApp.CreateItem(OL.OlItemType.olMailItem);
    Message.To = emailInfo.To;
    Message.CC = emailInfo.Cc ?? "";
    Message.Subject = emailInfo.Subject;
    if (filenameToAttach != null)
    {
        Message.Attachments.Add(filenameToAttach);
    }
 }