Outlook Attachment lost when sent from VB.net app...

jallen_gomedico used Ask the Experts™
I'm using the following code to send an email and pdf attachment.  The email goes out just fine and the attachment is there when I send to people on the Exchange server, but when I send to outside email addresses, the attachment is gone. (Email arrives OK though)

Any help would be appreciated.  I got this code from http://support.microsoft.com/?kbid=313803

Module Module1

    Sub Main()
        ' Create an Outlook application.
        Dim oApp As Outlook._Application
        oApp = New Outlook.Application()

        ' Create a new MailItem.
        Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET"
        oMsg.Body = "Hello World" & vbCr & vbCr

        ' TODO: Replace with a valid e-mail address.
        oMsg.To = "user@example.com"

        ' Add an attachment
        ' TODO: Replace with a valid attachment path.
        Dim sSource As String = "C:\Temp\Hello.pdf"
        ' TODO: Replace with attachment name
        Dim sDisplayName As String = "Hello.pdf"

        Dim sBodyLen As String = oMsg.Body.Length
        Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        Dim oAttach As Outlook.Attachment
        oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)

        ' Send

        ' Clean up
        oApp = Nothing
        oMsg = Nothing
        oAttach = Nothing
        oAttachs = Nothing
    End Sub

End Module
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Try sending it to two recipients, one inside and one outside. If the inside recipient gets the attachment and the outside doesn't it would almost point to your Exchange server deleting the attachment. Can you have your network admin follow the e-mail and see it there is a rule in the Exchange server that is deleting it before sending out? Another explanation could be the outside recipient's email server is doing the deletion. Did you try recipients with different email engines to see?

Thanks for the response.  Used all your suggestions and still kept pointing back to the Exchange Server.  Worked with our Network guy and still couldn't get it to stop stripping the attachment.  Found no rule that would cause this.  Same code in vb 6 works fine.  Which is frustrating.  Tried different recipients and ruled out that it was on the receivers end.

Ended up changing from Outlook to System.Net.Mail and using the following code which routes the mail away from our Exchange Server:
Imports System.Net.Mail
Sub Main()
        'Sub CreateMail_With_Attachment()

        Dim oMailMsg As New MailMessage

        Dim oMailClient As SmtpClient

        oMailMsg.From = New MailAddress("XXXX@YYYYY.com")

        oMailMsg.To.Add(New MailAddress("Receiver1@Outside.com"))
        oMailMsg.CC.Add(New MailAddress("Receiver2@Inside.com"))

        oMailMsg.Body = "Attached Sample Document for processing."

        oMailMsg.Subject = Sample Mail"

         oMailMsg.Attachments.Add(New Attachment("\\Server\Path\Sample.pdf"))

        oMailClient = New SmtpClient("Example.Provider.com")


     End Sub

Alan HardistyCo-Owner
Top Expert 2011

This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial