We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

developer • 13 years ago

yaaa but could you please help me how to send the smtp mails with queueing option.

Dave Transom • 13 years ago

@developer:
I think you might misunderstand the purpose of this. The main reason is so email is _not_ sent over the network - it avoids sending emails in development to the wrong people, and you can review _all_ the emails to verify the content is correct in a controlled environment.

The .eml files will stay on the file system, ready for you to open them with some kind of reader (I use the built-in Windows Live Mail).

developer • 13 years ago

when i implemented the code .eml file is stored into the specified path but we are not getting the email. Could you please help me.

Dave Transom • 13 years ago

@Mike: You might run into issues where multiple files are written to the drop folder from different threads - though in a development environment, if you're doing it directly after SmtpClient.Send() it _should_ be okay, but means you have to convolute your code by adding this. So I wouldn't bother.

@Hrshad: No, I haven't had a need for this. It shouldn't be hard to write another little c# app that has real (Network) settings for the mail server. But I'm not sure if there is support out of the box for reading .eml files and resending. I'm not sure what you're intending, but I would leave this as development only, and when deploying to production send directly via network. It feels like jumping through hoops otherwise.

Hrshad • 13 years ago

Good Article.

I want to read emails from folder and send it using schduler c# code, do you have any code for this?


Please send me on my email ID

Mike • 13 years ago

You can rename your .eml files with something like:
var _emailPickUpDirectory = "d:\temp\emails\";
var _latestEmail = new DirectoryInfo(_emailPickUpDirectory).GetFiles().OrderByDescending(file => file.LastWriteTime).First();
File.Move(_latestEmail.FullName, Path.Combine(_emailPickUpDirectory, "NewDynamicName.eml"));

Lincoln • 13 years ago

thank you, the explanation is great and the code is sweet.

Paul Bolejack • 14 years ago

With respect to the FileIOPermission error under medium trust, you can modify the medium trust config file (web_mediumtrust.config) on your development machine to give file IO permission on your drop directory. My testing indicated that only read and write were needed. So, for example, the new permission would be:
<IPermission class="FileIOPermission" version="1" Read="C:\SmtpMailDrop;$AppDir$" Write="C:\SmtpMailDrop;$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$"/>


Dave Transom • 16 years ago

@Steve: From the code you've given, it sounds like you're only creating one email and adding multiple recipients to it. Calling "message.Bcc.Add" simply adds more addresses. When it is 'dropped' to the pickup folder, there will be one email file, but you won't see who it's BCC'd to, because well, its a blind carbon copy.

If you view the file with a text editor (rather than outlook/outlook express, open with notepad), ALL the addresses should show up in the "X-Receiver" header at the top of the file.

However, if you want to send one separate email to each address (without the others knowing about it), you should create a new MailMessage each time, set the To address, and then call send.

Steve • 16 years ago

I tried. I am sending to a group using code below and then sending message-email did get dumpded to local directory but only one e-mail. not each email. Any thoughts?
If objDR.HasRows = True Then
lblEmails.Text = "" ' make sure it is reset
While objDR.Read()
If IsDBNull(objDR("email")) = False Then
recipient = CType(objDR("email"), String)
If recipient <> "" And recipient <> "steve@sfcas.com" Then
recipientcount = recipientcount + 1
If recipientcount - 1 >= intLowLim And recipientcount - 1 <= intUpLim Then

message.Bcc.Add(recipient)

arjan • 17 years ago

I agree, but it does not work in Medium Trust, you will get a FileIOPermission exception.

Dave Transom • 17 years ago

@Fluxtah:
Using email features suddenly got a lot easier once I realised this - Thanks Vista, wish I knew this when I was back on XP Pro ;)

@Kimm:
I'd see testing the content of email in different clients (hotmail, gmail, outlook, thunderbird, etc...) as a specific task to be undertaken.

Where as during normal development, you want to make sure that, a) the email is generated, and b) it has the right data in it (order line items, personalisations etc...)

So it does the job in that respect. Testing the design is another matter, where you'd _need_ actually send it. But that needs to be controlled, so you don't send email to non-test users.

Changes that come from this kind of testing are usually design tweaks, as opposed to anything high impact - unless it's your first rich content email, and you've just realised that most clients don't support or honour a lot of html and/or styles - so I would say it's okay to push this to your _staging_ server to finalise before going live. It's perhaps a little inconvenient for that single point only, but everything else is all pluses.

Fluxtah • 17 years ago

Never knew this, thanks! Saves having to run IIS on my dev machine.

Kimm • 17 years ago

I've always used the pickup directory, One little drawback to the "pickupnotsend" approach - usually i send out to different clients like hotmail, yahoo mail, outlook, oulook express etc. both in HTML and plain text to see if the content is diplayed as expected.

Well - you can monitor the flow of your mails by inspecting the folder, but you cannot inspect how the clients will display the content without actually sending the mails - So back to scratch - you still need some kind of server to actually send the EMLs.

Yuvan • 17 years ago

Thanks man...your artilce is clean and simple and to the point.Helped me to understand the delivery method in detail.

Ed • 18 years ago

I always use this to eliminate #3. However, I just found out that on our production server, IIS SMTP mails (from ASP.NET email dumps) are marked as spam most especially with Yahoo recipients. What do you use in your production/staging servers?

David Roberts • 18 years ago

Thank you.