Sending E-mail

D

DS

I have this code that works very well, except I want to send the contents of
a small report in the body of an E-Mail. Right now I'm transferring the
report to a txt file, works fine. How can I get that to the body of the E-
Mail?

Const cdoSendUsingPort = 2
Const cdoBasic = 1
Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields
.Item(strSch & "sendusing") = cdoSendUsingPort
.Item(strSch & "smtpserver") = "mail.optonline.net"
.Item(strSch & "smtpauthenticate") = cdoBasic
.Item(strSch & "sendusername") = "Big Corp"
.Item(strSch & "sendpassword") = "99"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.FROM = "Big Corp"
.sender = "(e-mail address removed)"
.TO = "(e-mail address removed)"
.subject = "SALES UPDATE"
.TextBody = "This should be the contents of the text file that is
from the report "
.SEND
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing

Thanks
DS
 
T

Tony Toews [MVP]

DS said:
I have this code that works very well, except I want to send the contents of
a small report in the body of an E-Mail. Right now I'm transferring the
report to a txt file, works fine. How can I get that to the body of the E-
Mail?

You'll need to get the contents of that report into a string variable.
Of course you can't do that. So the method is read the same data
that's on the report into a string variable. At least one recordset
read and maybe multiple looping through records.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
S

Stuart McCall

DS said:
I have this code that works very well, except I want to send the contents
of
a small report in the body of an E-Mail. Right now I'm transferring the
report to a txt file, works fine. How can I get that to the body of the
E-
Mail?

Const cdoSendUsingPort = 2
Const cdoBasic = 1
Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields
.Item(strSch & "sendusing") = cdoSendUsingPort
.Item(strSch & "smtpserver") = "mail.optonline.net"
.Item(strSch & "smtpauthenticate") = cdoBasic
.Item(strSch & "sendusername") = "Big Corp"
.Item(strSch & "sendpassword") = "99"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.FROM = "Big Corp"
.sender = "(e-mail address removed)"
.TO = "(e-mail address removed)"
.subject = "SALES UPDATE"
.TextBody = "This should be the contents of the text file that is
from the report "
.SEND
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing

Thanks
DS

Read the file into a string variable, like this:

Dim f As Integer, b As String

Open "MyFilePath.txt" For Binary Access Read as f
b = Space$(LOF(f))
Get #f, , b
Close f

Then assign it:

..TextBody = b
 
S

Stuart McCall

DS said:
I have this code that works very well, except I want to send the contents
of
a small report in the body of an E-Mail. Right now I'm transferring the
report to a txt file, works fine. How can I get that to the body of the
E-
Mail?

Const cdoSendUsingPort = 2
Const cdoBasic = 1
Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields
.Item(strSch & "sendusing") = cdoSendUsingPort
.Item(strSch & "smtpserver") = "mail.optonline.net"
.Item(strSch & "smtpauthenticate") = cdoBasic
.Item(strSch & "sendusername") = "Big Corp"
.Item(strSch & "sendpassword") = "99"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.FROM = "Big Corp"
.sender = "(e-mail address removed)"
.TO = "(e-mail address removed)"
.subject = "SALES UPDATE"
.TextBody = "This should be the contents of the text file that is
from the report "
.SEND
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing

Thanks
DS

Read the file into a string variable, like this:

Dim f As Integer, b As String

Open "MyFilePath.txt" For Binary Access Read as f
b = Space$(LOF(f))
Get #f, , b
Close f

Then assign it:

..TextBody = b
 

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

Sending E-Mail 11
WildCard 16
vbscript to send e-mail to exchange 2007 0
DoEvents 3
Send email to exchange versus SMTP 1
Using the CDO object to send email... 3
Send html in body 0
CDO & MailMessage problem 2

Top