tags:

views:

306

answers:

4

I am creating and sending emails using the System.Net.Mail namespace. The smtp.Send(mailMessage) call is being made within a using System.Transactions.TransactionScope block. If I do not create any email attachments then everything works fine. If I add any attachments (using mailMessage.Attachments.Add(attachment)) then no errors are thrown but the email is not delivered to the recipient - it just seems to disappear into the ether. Can anyone think of a reason why the addition of an attachment would result in the total failure of the email to be delivered (but no exception is raised!)

Thanks very much.

+1  A: 

The smpt server can be rejecting email with attachments. What type of file are you attaching? The server might confuse it with a virus or spam.

Giorgi
The user can attach any type of file. My testing involves attaching .txt files. Most users will be attaching .doc or .pdf files
DEH
+1  A: 

The mail server will be more suspicious of mails which have an attachment. You may need to set up a Sender Policy to convince the mail servers that you are who you claim to be.

runrunraygun
+1  A: 

Enable logging for System.Net.Mail, and view the log. This will at least verify that the mail has been sent. If it's been sent, and accepted, then you know the problem is on the mail server end, and you can quit chasing ghosts.

Here is a link on how to enable logging: http://systemnetmail.com/faq/4.10.aspx

Basically, add the following to your .config file:

<configuration>
  <system.diagnostics>
    <trace autoflush="true" />

    <sources>

      <source name="System.Net" >
        <listeners>
          <add name="MyTraceFile"/>
        </listeners>
      </source>

      <source name="System.Net.Sockets">
        <listeners>
          <add name="MyTraceFile"/>
        </listeners>
      </source>

    </sources>


    <sharedListeners>
      <add
        name="MyTraceFile"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="System.Net.trace.log"                />
    </sharedListeners>

    <switches>
      <add name="System.Net" value="Verbose" />
      <add name="System.Net.Sockets" value="Verbose" />
    </switches>
 </configuration>

Cheers!

Dave

dave wanta
A: 

The issue is with the vbscript within \mailroot on the server to catch all emails (C:\inetpub\mailroot\Script\catchall.vbs). This is not part of my app, but I believe is installed as part of the default SMTP server that comes with Windows Server.

This script is checking emails and attachments and is blocking emails based on the attachment. The following code in the file on line 62 has been commented out.

'if part.ContentMediaType = "application/octet-stream" then 'Executable attachment ' ProcessMessage = true ' Exit Function 'end if

Everything now working. Thanks for your help folks.

DEH