-1

I am creating a service that looks in a local directory for a .eml file and will send it if it exists. How do I do this without downloading a dll that I have to pay for? Should I be using a pickup directory, or is there a way to load the file and send it (with attachments) to one email address?

Edit: Here is what I have so far. I used CDO.Message to load the .eml message parts since the method .load(filePath) is only included in dll's that aren't open source. I then take the different message parts and save them to a EmailMessage object that will use the Exchange Service to send the email. I am having trouble separating the attachments from the msg object. Should I just have the attachment saved as a separate file from the .eml and attach it after the message is constructed?

            CDO.Message msg = new CDO.Message();
            ADODB.Stream stream = new ADODB.Stream();
            string fileName = "mail.eml";     
            string path = @"C:\Users\somebody\Desktop\Folder" + "\\" + fileName;
            stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty);
            stream.LoadFromFile(path);
            stream.Flush();
            msg.DataSource.OpenObject(stream, "_Stream");
            msg.DataSource.Save();
            stream.Close();

            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            service.Credentials = new WebCredentials("fromEmail@example.com", "Pass");
            service.AutodiscoverUrl("fromEmail@example.com", RedirectionUrlValidationCallback);

            if (File.Exists(path))
            {
                EmailMessage message = new EmailMessage(service);
                message.Subject = msg.Subject;
                message.Body = msg.TextBody;
                msg.To = "toEmail@example.com";
                msg.From = "toEmail@example.com";
                foreach (var attachment in msg.Attachments)
                {
                    var attach = attachment;
                }                  
                message.Send();

                Console.WriteLine("Message sent!");
            }
Lohkii
  • 43
  • 1
  • 2
  • 10
  • I know about File.Exists that's not the issue. I need to be able to load a .eml file and send it if it does exist. Everything I have Googled has given me simple solutions where the .eml file is parsed and prepared to send, but I have to download their dll for a price. – Lohkii Dec 16 '14 at 17:54

1 Answers1

-1

Here is a pseudo-code for you:

doTheJob(directory)
{
   files = list files from directory;
   foreach file in files
   {
      mail = create mail data from file;
      send(mail); 
   }
}

The tricky part is create mail data from file but for sure you will find an asnwer on SO about reading EML files in C#.

Note: This answer is as general as the question is...

Konrad Kokosa
  • 16,563
  • 2
  • 36
  • 58
  • Yes I realized that my question was too general. I have edited what I have so far. Am I on the right track? – Lohkii Dec 16 '14 at 19:02