Results 1 to 3 of 3
  1. #1
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104

    send email with attachment using Gmail (CDO)

    Hi all,

    I have lots of working ideas from the interweb about how to send emails using gmail, but I cannot crack the addattachment part.
    No matter what variations I use, I cannot attach a zip file from a specific location, which is defined in [Me.Attachment], a field on my 'code-executing' form.
    The code below has been edited for security and privacy purposes, but trust me, when I put the correct email addresses and password in, the code works apart from the attachment!


    Anybody got any help please?

    Code:
            Dim strMailto As String
            strMailto = "someone@somewhere.com"
            Dim strMailFrom As String
            strMailFrom = "me@somewhere.com"
            Dim strSubject As String
            strSubject = "My Subject from - " & DtSite
            Dim StrBody As String
            StrBody = "Please find attached the latest subject matter.   Thank you" & vbCrLf & "Please do not reply to this email."
            Dim msg As Object
            Set msg = CreateObject("CDO.Message")
            msg.FROM = strMailFrom
            msg.To = strMailto
            msg.Subject = strSubject
            msg.TextBody = StrBody
            msg.replyto = strMailFrom
    
            If IsNull(Me.Attachment) = False Then
                 Dim strAttachment As String
                 strAttachment = Me.Attachment
                 msg.addattachment "file://" & strAttachment & ""
            End If
            
            msg.configuration.Fields("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = "smtp.gmail.com"
            msg.configuration.Fields("http://schemas.microsoft.com/cdo/con...smtpserverport") = 465
            msg.configuration.Fields("http://schemas.microsoft.com/cdo/con...tion/sendusing") = 2
            msg.configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...n/sendusername") = "someone@gmail.com"
            msg.configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...n/sendpassword") = "password"
            msg.configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...ion/smtpusessl") = True
            msg.configuration.Fields.Item("http://schemas.microsoft.com/cdo/con...tpauthenticate") = 1
            msg.configuration.Fields.Update
            msg.Send

  2. #2
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I found this..

    I do see that the code example below is doing something with

    Dim Iconf as object
    Set iconf.createobject("CDO.Configuration")


    Take a look at below.


    http://www.mrexcel.com/forum/excel-q...lications.html

  3. #3
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    Thanks RedBull

    Trie d that, but still no success...
    There are millions of posts about adding an attachment for CDO, but they all point to .addattachment, and that is just not working!!!
    I am so frustrated, and cannot find a solution...
    anybody else got any other clues/tips?

    cheers
    Pete

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send email with Attachment
    By scoe in forum Programming
    Replies: 3
    Last Post: 09-23-2014, 03:02 AM
  2. How to send email without attachment
    By behnam in forum Programming
    Replies: 3
    Last Post: 07-30-2014, 08:24 AM
  3. Replies: 5
    Last Post: 11-26-2013, 11:21 AM
  4. Send Email with Attachment VBA Code
    By kevins in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 01:21 PM
  5. Beginner trying to send email with attachment
    By ahm in forum Programming
    Replies: 2
    Last Post: 03-24-2009, 08:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums