Dim HtmlBody 'To store html body
Dim EmailSubject 'To store email Subject
Dim EmailFrom 'To store email From
Dim EmailTo 'To store email To
Dim EmailBcc 'To store email BCC
Dim EmailCc 'To store email CC
Dim EmailSMTPServer 'To store SMTP Server name or address
Dim fso 'To declare File System Object for file access
Dim filename 'To declare filename for email content
Dim myattachment 'To declare filename for attachment
Dim insured
Dim policy
Dim EmailBody
Dim hlink
Dim cemail
Dim pathz
insured = PropertyValues.SearchForProperty(1020).TypedValue.DisplayValue
policy = PropertyValues.SearchForProperty(1157).TypedValue.DisplayValue
cemail = PropertyValues.SearchForProperty(1267).TypedValue.DisplayValue
pathz=PropertyValues.SearchForProperty(1190).TypedValue.DisplayValue
pathz = Left(pathz, Len(pathz) - 1)
'Err.Raise MFScriptCancel,path3
'Initialization of Email Configuration
EmailSMTPServer = "smtp.googlemail.com"
EmailSubject = "Claim" & policy
EmailFrom = 'enter address here
EmailTo = cemail
EmailBcc = ""
EmailCc = ""
insured = PropertyValues.SearchForProperty( 1020 ).TypedValue.DisplayValue
'declare file to use as HTML email content
'filename = "c:\myemail.html"
EmailBody = "Dear, " & insured & " kindly find the document attached."
'declare file to use as attachment
myattachment = pathz
'Creating File System Object and loading HTML file into email content
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set ObjOutFile = fso.OpenTextFile(filename,1)
'HtmlBody = objOutFile.ReadAll
'Send the HTML email
'SendEmail(HtmlBody)
SendEmail(EmailBody)
'Specify Email sending properties
Function GetCDOFromProperties()
Dim SMTPServer, SMTPPort, SMTPAuthenticate, SMTPUserName, SMTPPassword, SMTPTimeout, SMTPProxyServer, SMTPProxyBypass
SMTPServer = EmailSMTPServer
SMTPPort = "465"
SMTPAuthenticate = "1"
SMTPUserName = 'enter username
SMTPPassword = 'enter password
SMTPTimeout = "5000"
SMTPProxyServer = ""
SMTPProxyBypass = ""
Set GetCDOFromProperties = ConfigureCDO(SMTPServer, SMTPPort, SMTPAuthenticate, SMTPUserName, SMTPPassword, SMTPTimeout, SMTPProxyServer, SMTPProxyBypass)
End Function
'Configure CDO Email
Function ConfigureCDO(SMTPServer, SMTPPort, SMTPAuthenticate, SMTPUserName, SMTPPassWord, SMTPTimeout, SMTPProxyServer, SMTPProxyBypass)
Dim Conf
' Setup SMTP Options
Set Conf = CreateObject("CDO.Configuration")
'Specifies the method used to send messages. 1 - Pickup; 2 - Port. If a local SMTP service is available, this field defaults to 1
Conf.Fields.Item("schemas.microsoft.com/.../sendusing") = 2
' The pickup directory for the local SMTP service. This value is set automatically when the SMTP service is installed.
'Conf.Fields.Item("schemas.microsoft.com/.../smtpserverpickupdirectory") = "c:\mailroot\pickup"
' The name (DNS) or IP address of the machine hosting the SMTP service through which messages are to be sent.
Conf.Fields.Item("schemas.microsoft.com/.../smtpserverport") = strnullcheck(SMTPPort)
' The port on which the SMTP service specified by the smtpserver field is listening for connections. The default and well-known port for an SMTP service is 25.
Conf.Fields.Item("schemas.microsoft.com/.../smtpserver") = strnullcheck(SMTPServer)
' SMTP is using SSL; Default False
Conf.Fields.Item("schemas.microsoft.com/.../smtpusessl") = True
' 0 - Do not auth; 1 - Basic (clear text auth); 2 - Use NTLM authentication (Secure Password Authentication in Microsoft? Outlook? Express). The current process security context is used to authenticate with the service.
Conf.Fields.Item("schemas.microsoft.com/.../smtpauthenticate") = strnullcheck(SMTPAuthenticate)
Conf.Fields.Item("schemas.microsoft.com/.../sendusername") = strnullcheck(SMTPUserName)
Conf.Fields.Item("schemas.microsoft.com/.../sendpassword") = strnullcheck(SMTPPassWord)
' The user's email address used when connecting to the SMTP service.
'Conf.Fields.Item("schemas.microsoft.com/.../sendemailaddress") = "demo@techedge.co.ke"
' Indicates the number of seconds to wait for a valid socket to be established with the SMTP service before timing out. Default is 30
Conf.Fields.Item("schemas.microsoft.com/.../smtpconnectiontimeout") = strnullcheck(SMTPTimeout)
' The proxy server to use when accessing HTTP resources. Both the name (or IP address) of the proxy machine and the port number must be specified using the format "servername:port."
Conf.Fields.Item("schemas.microsoft.com/.../urlproxyserver") = strnullcheck(SMTPProxyServer) '"server:80"
' Used to specify that for local addresses, the proxy (set with urlproxyserver) should be bypassed. The value of the string, if set, should only be "<local>". This is the same value used with Internet Explorer when setting a proxy with bypass for local addresses.
Conf.Fields.Item("schemas.microsoft.com/.../urlproxybypass") = strnullcheck(SMTPProxyBypass) '"<local>"
Conf.Fields.Update
Set ConfigureCDO = Conf
End Function
'Used to check for blank values in CDO Configuration
Function strnullcheck(varString)
If Isnull(varString) Then
strnullcheck = ""
Else
strnullcheck = varString
End If
End Function
'Send the email (including an attachment)
Function SendEmail(HtmlBody)
Set objMessage = CreateObject("CDO.Message")
objMessage.Configuration = GetCDOFromProperties()
'Email header
objMessage.Subject = EmailSubject
objMessage.From = EmailFrom
objMessage.To = EmailTo
objMessage.Bcc = EmailBcc
objMessage.Cc = EmailCc
'Add Email Attachment
objMessage.AddAttachment myattachment
'The line below shows how to send using HTML included directly in your script
objMessage.HTMLBody = HtmlBody
objMessage.Send
Set objMessage = nothing
HtmlBody = ""
End Function
The challenge however is picking a document from Mfiles (maybe a view) and attaching it to the email. Anyone who has a solution on how to attach documents with a path on Mfiles.