Sending E-Mail

D

DS

I'm sorry I posted this before, and for whatever reason the answer is now
gone. I have a new computer and my newsgroups are totally messed up.
Sometimes I can post, sometimes I can, Things are here then they are not!
Anyways heres my question again.

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

Once again I am sorry for the repost,
Thanks
DS
 
S

Stuart McCall

DS said:
I'm sorry I posted this before, and for whatever reason the answer is now
gone. I have a new computer and my newsgroups are totally messed up.
Sometimes I can post, sometimes I can, Things are here then they are not!
Anyways heres my question again.

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

Once again I am sorry for the repost,
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
 
D

DS

OK finally got around to trying it.
I'm getting an error message on the Open line.
Message Error 52
Bad File name

Dim f As Integer, b As String
Open "C:\SMS\SalesUpdate.txt" For Binary Access Read As f
b = Space$(LOF(f))
Get #f, , b
Close f

Any help appreciated.
DS
 
S

Stuart McCall

DS said:
OK finally got around to trying it.
I'm getting an error message on the Open line.
Message Error 52
Bad File name

Dim f As Integer, b As String
Open "C:\SMS\SalesUpdate.txt" For Binary Access Read As f
b = Space$(LOF(f))
Get #f, , b
Close f

Any help appreciated.
DS

Access is giving you the correct error message (for once :)

There's something up with "C:\SMS\SalesUpdate.txt". You need to check it,
because nothing else can cause this error. It's either missing altogether or
part of it is mis-spelt.
 
D

Douglas J. Steele

You haven't assigned a value to f.

Before the Open statement, you need

f = Freefile()
 
S

Stuart McCall

Stuart McCall said:
Access is giving you the correct error message (for once :)

There's something up with "C:\SMS\SalesUpdate.txt". You need to check it,
because nothing else can cause this error. It's either missing altogether
or part of it is mis-spelt.

Please ignore that last message. Doug Steele kindly pointed out that I'd
missed an essential line of code. Here's how it should read:

Dim f As Integer, b As String
f = FreeFile
Open "C:\SMS\SalesUpdate.txt" For Binary Access Read As f
b = Space$(LOF(f))
Get #f, , b
Close f
 

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 3
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