Quote:
Originally Posted by ShellR
Do you think it's a good idea perhaps to first check to see if the 3rd party has outlook on their pc first, if not check to see what mail server they are using and then use that server to send the attachment?
I assume it would be some sort of IF ELSE statement? what do you think?
|
You could check if the user has Outlook installed e.g. using the following function to read the registry.
Code:
Function IsOutlook() As Boolean
Dim myWS As Object
Dim RegKey As String
Dim Key As String
Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\"
On Error Resume Next
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'read key from registry
RegKey = myWS.RegRead(Key)
If RegKey = "Microsoft Outlook" Then
IsOutlook = True
End If
lbl_Exit:
Exit Function
End Function
If the result is true you could use the Outlook routine to send the message.
If it is false then what? Your CDO routine is of no use as you will have no idea of the users' email data to apply to the macro. Perhaps it would be preferable to simply enter a link to your e-mail on the form and ask the user to send the completed form to that address. Or maybe you could create a web form and forget about using Word altogether?
Quote:
Originally Posted by ShellR
So, now with the CDO corrections, I keep getting file not found even though the file was created.
|
As I mentioned in my last post, your code as posted doesn't know what strFileB refers to. How did you indicate to the macro what that variable refers to?
One way to do it is to create a sub using your posted code and call that from the PDF code. After the line
Code:
ActiveDocument.SaveAs2 strFileName, FileFormat:=wdFormatPDF
add a line to call the following macro
Code:
SendAttachment strfilename
Code:
Sub SendAttachment(strFileB As String)
Dim sender_email, email_message, email_message2, reply_address, sender_name As String
Dim Mail As New Message
Dim Cfg As Configuration
On Error GoTo Error_Handling
Set Cfg = Mail.Configuration
'SETUP MAIL CONFIGURATION FIELDS
Cfg(cdoSendUsingMethod) = cdoSendUsingPort
Cfg(cdoSMTPServer) = "SMTP.gmail.com"
Cfg(cdoSMTPServerPort) = 465
Cfg(cdoSMTPAuthenticate) = cdoBasic
Cfg(cdoSMTPUseSSL) = True
Cfg(cdoSendUserName) = "vbatestingtest@gmail.com"
Cfg(cdoSendPassword) = "coding123$$"
Cfg.Fields.Update
'SEND EMAIL
With Mail
.From = "vbatestingtest@gmail.com"
.ReplyTo = "vbatestingtest@gmail.com"
.To = "shellreid2004@yahoo.ca"
.CC = "disegnifenice@gmail.com"
.BCC = ""
.Subject = "testing form send"
.HTMLBody = "testing"
.AddAttachment (strFileB)
.send
End With
Error_Handling:
If Err.Description <> "" Then MsgBox Err.Description
lbl_Exit:
Exit Sub
End Sub
P.S. When posting code listings, use the Code tags # to format the code.