Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    59

    Unanswered: Need help with sending attachments

    Hi,
    I have designed a sendmail function which I'm really happy with. It does exactly what I need to do. However I am having some problems trying to add attachments to it. I have looked at many different examples using CDO, objMessage and .Add.Attachments but can't work out how I would integrate these into my code. Could someone take a quick look at the code and let me know what would be the best way for me to add attachments???

    Code:
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSubject As String
    Dim strEmailAddress As String
    Dim strEMailMsg As String
    Dim ingCounter As Integer
    Dim intCount As Integer
    
    ' Write messagebox content to a file
        
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set theFile = fso.CreateTextFile("C:\Email.htm", vbTrue)
    
    
            theFile.WriteLine "<HTML>"
            theFile.WriteLine "<BODY style='font-family:Century Gothic;'>"
            theFile.WriteLine "<p></p>"
            theFile.WriteLine [Message]
            theFile.WriteLine "<br />"
    
    ' Append the user's signature file
    
            theFile.WriteLine fso.OpenTextFile("K:\Admin & office\logo & letterhead\email-signature.html").ReadAll
            theFile.WriteLine "</BODY>"
            theFile.WriteLine "</HTML>"
            theFile.Close
            
          
    ' Close the file which now contains the email body and signature and read the content into myHTML
            
            Set f = fso.OpenTextFile("C:\Email.htm", 1)
            MyHTML = f.ReadAll
            f.Close
    
    strSubject = [Subject]
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("qryEmailOut")
    
    rst.MoveFirst
    Do Until rst.EOF
        
        strEmailAddress = rst![email address]
        strEMailMsg = MyHTML
    
        'EMAIL USER DETAILS & ATT REPORT
        DoCmd.SendObject , , acFormatRTF, strEmailAddress, _
        , , strSubject, strEMailMsg, False, False
        
    
        rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing
        
    End Sub
    Thanks!
    Russ

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Ya can't do it with SendObject as far as I know.

    BTW, why write a file and then read it into a variable?... why not just build the html straight into the variable?


    ' Write content to a variable
    Code:
    strEMailMsg = "<HTML>" & _
                       "<BODY style='font-family:Century Gothic;'>" & _
                       "<p></p>" & _
                       [Message] & _
                       "<br />"
    
    ' Append the user's signature file
    etc
    Anyway, you might have to send your mail via using an alternative to SendObject, such as this:

    http://www.dbforums.com/showthread.php?t=1626609
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Nov 2008
    Posts
    59
    I was hoping at some point to have a preview of the e-mail before sending which is why I have written to an external file. My theory being that I could then load up email.htm before sending it. I'm not actually sure how I'm going to do this yet so if you have any ideas please let me know.

    Cheers!

Posting Permissions

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