1

I am storing Emails in a Directory, like the following. How do I go about, programatically, sending those at a later time, say an event of some sorts

smtpClient.PickupDirectoryLocation = "C:\\EmailHoldingBin\\";

smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;

Refracted Paladin
  • 12,096
  • 33
  • 123
  • 233

3 Answers3

4

Files stored using the PickupDirectoryLocation are written in raw SMTP (MIME/EML) format and are meant to be processed by the local SMTP server which is typically IIS. While the SmtpClient and the MailMessage objects can effectively "write" as raw SMTP/MIME they have no provision for reading such files. If you must read these files you'll need to write your own parser or use one already created such as this one.

Chris Haas
  • 53,986
  • 12
  • 141
  • 274
1

I agree with the answer from gangelo

Another point:
The Pickup directory only works if there is some service (like IIS) picking up the mail messages stored there and sends them - so you need to configre IIS for this to work...

EDIT - Exchange pickup folder as per comment:

for example with Exchange 2007 http://www.msexchange.org/articles_tutorials/exchange-server-2007/management-administration/exchange-pickup-folder.html

and for Exhange 2010 http://technet.microsoft.com/en-us/library/bb124230.aspx

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • I have a rather unique setup. I am not using the IISPickupDirectory but a local one. I have a service that runs on each users laptop that detects when they are back on OUR network which then triggers some events that were stored when they were offline. I would be adding the "routine" for sending off the `.eml`s in this process. – Refracted Paladin Jul 26 '11 at 18:38
  • So in that routine you just need to copy the mails from the local folder to central pickup folder once the users are back - never tried it but should work... – Yahia Jul 26 '11 at 18:39
  • Interesting, so the Exchange Server itself has a pickup folder and I just need to identify that. I will look into this. – Refracted Paladin Jul 26 '11 at 18:41
  • This works slick. My program creates the .eml's(with attachment included) and stores them in a local, user, folder and then after detecting our network moves the physical files to the Exchange Pickup Folder where Exchange automatically processes them. Works slick! – Refracted Paladin Jul 27 '11 at 16:12
0

You need to call smtpClient.Send(System.Net.Mail.MailMessage) but not before setting From, To, Subject and Body properties of System.Net.Mail.MailMessage.

gangelo
  • 3,034
  • 4
  • 29
  • 43