+ Reply to Thread
Results 1 to 4 of 4

Problem in mail attachment when using CDO

  1. #1

    Problem in mail attachment when using CDO

    Hi all,

    I'm using CDO to send email from excel and have some problems with
    attachments. If correct smtp-address is provided mail is sent with
    attachment, but the attachment is somehow messed up. The original size
    of the file is about 150kb but when I open the mail attachemnt is only
    about 15kb... And then of course the attachment cannot be opened. What
    might be the reason for this? The attachment is the same workbook I'm
    working on and has been saved earlier. Code below.

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant
    Application.ScreenUpdating = False

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    iConf.Load -1
    Set Flds = iConf.Fields
    With Flds

    ..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    ..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    smtp

    ..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
    = 25
    .Update
    End With
    With iMsg
    Set .Configuration = iConf
    If toAdd <> "" Then
    .To = toAdd
    .From = """Me"" <[email protected]>"
    .subject = subject
    .AddAttachment "C:\excelFile.xls"
    .Send

    Set iMsg = Nothing
    Set iConf = Nothing
    Application.ScreenUpdating = True
    Application.Quit
    End If
    End With

    Thanks,
    Jape


  2. #2
    NickHK
    Guest

    Re: Problem in mail attachment when using CDO

    According to Ron de Bruin's site for all things Excel/Email:
    http://www.rondebruin.nl/cdo.htm
    <Quote>
    Don't remove the TextBody line in the code. If you do you can't open the
    attachment (bug in CDO).
    If you don't want to have text in the body use this then .TextBody = ""
    </Quote>
    I see you do not have .TextBody .

    Does that help ?

    NickHK

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi all,
    >
    > I'm using CDO to send email from excel and have some problems with
    > attachments. If correct smtp-address is provided mail is sent with
    > attachment, but the attachment is somehow messed up. The original size
    > of the file is about 150kb but when I open the mail attachemnt is only
    > about 15kb... And then of course the attachment cannot be opened. What
    > might be the reason for this? The attachment is the same workbook I'm
    > working on and has been saved earlier. Code below.
    >
    > Dim iMsg As Object
    > Dim iConf As Object
    > Dim Flds As Variant
    > Application.ScreenUpdating = False
    >
    > Set iMsg = CreateObject("CDO.Message")
    > Set iConf = CreateObject("CDO.Configuration")
    > iConf.Load -1
    > Set Flds = iConf.Fields
    > With Flds
    >
    > .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    >
    > .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    > smtp
    >
    > .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
    > = 25
    > .Update
    > End With
    > With iMsg
    > Set .Configuration = iConf
    > If toAdd <> "" Then
    > .To = toAdd
    > .From = """Me"" <[email protected]>"
    > .subject = subject
    > .AddAttachment "C:\excelFile.xls"
    > .Send
    >
    > Set iMsg = Nothing
    > Set iConf = Nothing
    > Application.ScreenUpdating = True
    > Application.Quit
    > End If
    > End With
    >
    > Thanks,
    > Jape
    >




  3. #3
    NickHK
    Guest

    Re: Problem in mail attachment when using CDO

    Also, according to Ron, you can't send the active workbook. .SaveCopyAs
    first and send that in the attachment.

    NickHK

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi all,
    >
    > I'm using CDO to send email from excel and have some problems with
    > attachments. If correct smtp-address is provided mail is sent with
    > attachment, but the attachment is somehow messed up. The original size
    > of the file is about 150kb but when I open the mail attachemnt is only
    > about 15kb... And then of course the attachment cannot be opened. What
    > might be the reason for this? The attachment is the same workbook I'm
    > working on and has been saved earlier. Code below.
    >
    > Dim iMsg As Object
    > Dim iConf As Object
    > Dim Flds As Variant
    > Application.ScreenUpdating = False
    >
    > Set iMsg = CreateObject("CDO.Message")
    > Set iConf = CreateObject("CDO.Configuration")
    > iConf.Load -1
    > Set Flds = iConf.Fields
    > With Flds
    >
    > .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    >
    > .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    > smtp
    >
    > .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
    > = 25
    > .Update
    > End With
    > With iMsg
    > Set .Configuration = iConf
    > If toAdd <> "" Then
    > .To = toAdd
    > .From = """Me"" <[email protected]>"
    > .subject = subject
    > .AddAttachment "C:\excelFile.xls"
    > .Send
    >
    > Set iMsg = Nothing
    > Set iConf = Nothing
    > Application.ScreenUpdating = True
    > Application.Quit
    > End If
    > End With
    >
    > Thanks,
    > Jape
    >




  4. #4

    Re: Problem in mail attachment when using CDO

    Yep, that did the trick. All the thanks in the world to you! This
    helped me a lot...

    Jape

    > According to Ron de Bruin's site for all things Excel/Email:
    > http://www.rondebruin.nl/cdo.htm
    > <Quote>
    > Don't remove the TextBody line in the code. If you do you can't open the
    > attachment (bug in CDO).
    > If you don't want to have text in the body use this then .TextBody = ""
    > </Quote>
    > I see you do not have .TextBody .
    >
    > Does that help ?
    >
    > NickHK
    > > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1