Send report through Gmail

bbwolff

Registered User.
Local time
Tomorrow, 00:18
Joined
Oct 1, 2013
Messages
116
I use this to send email msgs through gmail
found it on the net somewhere, adapted a bit and it works.

Code:
Private Function fSendGmail() As Boolean 'Returns True if No Errors are Generated
On Error GoTo Err_ErrorHandler
fSendGmail = True



Const conStrPrefix As String = "http://schemas.microsoft.com/cdo/configuration/"
Const conCdoSendUsingPort As Integer = 2
Const conSendPassword As String = "mypassword"
Const conCdoBasic As Integer = 1
Const conSendUserName As String = "mymail@gmail.com"
Const conStrSmtpServer As String = "smtp.gmail.com"
Const conCdoSmtpUseSSL As Boolean = True
Const conCdoSmtpServerPort As Integer = 465

Dim oMsg As Object
Dim oConf As Object


Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
Set oMsg.Configuration = oConf

With oMsg
    .to = "yourmail@gmail.com"
    .From = "Pikica in Pokica <mymail@gmail.com>"
    .subject = "test"
    .textBody = "great, it works " & vbCrLf & "'Me.BodyText.Value'"
End With
            
''Set Delivery Options
            With oConf.Fields
                .Item(conStrPrefix & "sendusing") = conCdoSendUsingPort
                .Item(conStrPrefix & "smtpserver") = conStrSmtpServer
                .Item(conStrPrefix & "smtpauthenticate") = conCdoBasic
                .Item(conStrPrefix & "sendusername") = conSendUserName
                .Item(conStrPrefix & "sendpassword") = conSendPassword
                .Item(conStrPrefix & "smtpusessl") = conCdoSmtpUseSSL
                .Item(conStrPrefix & "smtpserverport") = conCdoSmtpServerPort
                .Update 'Commit Changes
            End With

oMsg.send

Exit_ErrorHandler:

    Set oMsg.Configuration = Nothing
    Set oConf = Nothing
    Set oMsg = Nothing
    Exit Function

Err_ErrorHandler:
    If Err.Number <> 0 Then fSendGmail = False etc, etc
        
End Function      'fSendGmail

I'd like to send report attached to this as pdf or rtf. How should I go about it.
I know how to create pdf and save it.(DoCmd.OutputTo acOutputReport, "My Report", acFormatPDF, strPath, True) But where do I attach that here? Is it necessary to save the file first?
 
got a solution more or less

.AddAttachment "C:\DL\test.pdf"

now, do i have to save the report first, or can it make a virtual copy?
more of an academical question really as this works fine enough
 
You have to save it first, but you can delete it after the email is sent.
 
one more problem
I'm trying to save to user/documents folder. i use this

Code:
strusername = Environ("username")
strpath = "C:\Users\" & strusername & "\documents\test.pdf"
DoCmd.OutputTo acOutputReport, "Operacije1", acFormatPDF, strpath, True

how do i format addattachement part

.AddAttachment "" & strpath or .AddAttachment strpath or even .AddAttachment "' & strpath & '" don't work for me
 
The middle one should work. Where exactly do you have it?
 
Now it works. Not sure what was wrong, maybe a different issue.
 

Users who are viewing this thread

Back
Top Bottom