Pass Arguments to CDO_Mail_Auto

J

Johnny

I am using Ron DeBruin's CDO_Mail_Auto routine. I would like to call
this routine from another VBA routine. I want to pass the value of
cell A1 and cell A3 into CDO_Mail_Auto, so that the value of those
cells become part of the emailed message.

Basically, I want to evaluate a cell at A7 for "TRUE" or "FALSE", and
if "TRUE", send an email about that row of data, specifically with the
contents of A1 and A3.

I'll attach my working copy of CDO_Mail_Auto here, with the email and
password info XXXXX'd out. Any help would be appreciated.

Thanks
John

--------------------------------------------

Sub CDO_Mail_Auto()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/
smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/
smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/
sendusername") = "(e-mail address removed)"
.Item("http://schemas.microsoft.com/cdo/configuration/
sendpassword") = "XXXXXXX"
.Item("http://schemas.microsoft.com/cdo/configuration/
smtpserver") = "smtp.gmail.com"

.Item("http://schemas.microsoft.com/cdo/configuration/
sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/
smtpserverport") = 25
.Update
End With

strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"

With iMsg
Set .Configuration = iConf
.To = "XXXXXXXXX"
.CC = ""
.BCC = ""
' Note: The reply address is not working if you use this Gmail
example
' It will use your Gmail address automatic. But you can add
this line
' to change the reply address .ReplyTo = "(e-mail address removed)"
.From = """XXXXXXXX"" <[email protected]>"
.Subject = "Important message"
.TextBody = strbody
.Send
End With

End Sub
 
R

Ron de Bruin

See the tips on the CDO page

Dim strbody As String
With Sheets("Sheet1")
strbody = "Hi there" & vbNewLine & vbNewLine & _
.Range("A1") & vbNewLine & _
.Range("A2") & vbNewLine & _
.Range("A3") & vbNewLine & _
.Range("A4")
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top