I use this to send email msgs through gmail
found it on the net somewhere, adapted a bit and it works.
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?
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?