From: mistral on
I need help implement data emailing function instead of writing data
to hard drive. This code snippet below retrieve some data then show
MsgBox prompt to choose write data to hard drive or just show data in
message box.
I want modify code that this data were sent out by email, without
writing on drive or MsgBox prompts. Emailing will be use CDO, without
installing the SMTP service.

<-- start code
Public Function sGetSomeData()
.... ... ...
.... ... ...
.... ... ...
sGetSomeData = sSomeData

End Function

Public Function Question()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim Ans

Ans = MsgBox("Yes = Write this data to the C Drive and No = Prompt
with data",4)

If Ans = vbYes then

Set oOutFile = objFSO.CreateTextFile("c:\Write_My_Data.txt")

oOutFile.WriteLine sGetSomeData
else
wscript.echo sGetSomeData
End If
End Function

call Question
-- end code -->

Below is generic code that uses CDO to send email:

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = "me(a)my.com"
objMessage.To = "test(a)paulsadowski.com"
objMessage.TextBody = "This is sample message text."

'==This section provides the configuration information for the remote
SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"smtp.myserver.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send

How to implement emailing part in main code correctly?

thanks.
mistral

From: Bart Perrier on
I do this very thing with a number of jobs and have taken advantage of the
Message Priority after a long hard battle to figure it out.

Where you have the wscrpt.echo use a variable instead. Such as
strEmailBody = strEmailBody & yourData. If you are using HTML then you will
need to add the HTML tags as well.

Here is the method I call to send email from one particular script. Watch
out for the wordwrap.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub SendEmail
Dim objEmail

' this is actually called to generate an HTML email and insert the HTML tags
Call GenerateMessage

Set objEmail = CreateObject("CDO.Message")

' these are constants defined at the begining of the script.
' you can also make the TO address a variable if you need to send different
messages to different recipients.
objEmail.From = FROM_ADDRESS
objEmail.To = TO_ADDRESS
objEmail.CC = CC_ADDRESS
objEmail.BCC = BCC_ADDRESS
objEmail.Subject = EMAIL_SUBJECT
objEmail.HTMLBody = strEmailBody

' more constants at the top
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") =
SMTP_SENDUSING
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
SMTP_SERVER_PORT
objEmail.Configuration.Fields.Update

objEmail.Send

End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hope this helps.
Bart


"mistral" <polychrom(a)softhome.net> wrote in message
news:1170182062.663758.44240(a)h3g2000cwc.googlegroups.com...
>I need help implement data emailing function instead of writing data
> to hard drive. This code snippet below retrieve some data then show
> MsgBox prompt to choose write data to hard drive or just show data in
> message box.
> I want modify code that this data were sent out by email, without
> writing on drive or MsgBox prompts. Emailing will be use CDO, without
> installing the SMTP service.
>
> <-- start code
> Public Function sGetSomeData()
> ... ... ...
> ... ... ...
> ... ... ...
> sGetSomeData = sSomeData
>
> End Function
>
> Public Function Question()
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim Ans
>
> Ans = MsgBox("Yes = Write this data to the C Drive and No = Prompt
> with data",4)
>
> If Ans = vbYes then
>
> Set oOutFile = objFSO.CreateTextFile("c:\Write_My_Data.txt")
>
> oOutFile.WriteLine sGetSomeData
> else
> wscript.echo sGetSomeData
> End If
> End Function
>
> call Question
> -- end code -->
>
> Below is generic code that uses CDO to send email:
>
> Set objMessage = CreateObject("CDO.Message")
> objMessage.Subject = "Example CDO Message"
> objMessage.Sender = "me(a)my.com"
> objMessage.To = "test(a)paulsadowski.com"
> objMessage.TextBody = "This is sample message text."
>
> '==This section provides the configuration information for the remote
> SMTP server.
> objMessage.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> 'Name or IP of Remote SMTP Server
> objMessage.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> "smtp.myserver.com"
> 'Server port (typically 25)
> objMessage.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
> 25
> objMessage.Configuration.Fields.Update
> '==End remote SMTP server configuration section==
> objMessage.Send
>
> How to implement emailing part in main code correctly?
>
> thanks.
> mistral
>


From: mistral on
On 30 ���., 23:13, "Bart Perrier" <bart_perr...(a)hotmail.com> wrote:
> I do this very thing with a number of jobs and have taken advantage of the
> Message Priority after a long hard battle to figure it out.

> Where you have the wscrpt.echo use a variable instead. Such as
> strEmailBody = strEmailBody & yourData. If you are using HTML then you will
> need to add the HTML tags as well.

> Here is the method I call to send email from one particular script. Watch
> out for the wordwrap.

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Sub SendEmail
> Dim objEmail

> ' this is actually called to generate an HTML email and insert the HTML tags
> Call GenerateMessage

> Set objEmail = CreateObject("CDO.Message")

> ' these are constants defined at the begining of the script.
> ' you can also make the TO address a variable if you need to send different
> messages to different recipients.
> objEmail.From = FROM_ADDRESS
> objEmail.To = TO_ADDRESS
> objEmail.CC = CC_ADDRESS
> objEmail.BCC = BCC_ADDRESS
> objEmail.Subject = EMAIL_SUBJECT
> objEmail.HTMLBody = strEmailBody

> ' more constants at the top
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") =
> SMTP_SENDUSING
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
> SMTP_SERVER_PORT
> objEmail.Configuration.Fields.Update

> objEmail.Send

> End Sub
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> Hope this helps.
> Bart
--------------------

thanks, Bart. Not fully clear, how to interface mailing code with main
script.

like this:

<-- start code
Public Function sGetSomeData()
.... ... ...
.... ... ...
.... ... ...
sGetSomeData = sSomeData

End Function

else
wscript.echo strEmailBody = strEmailBody & sGetSomeData
End If
End Function

Sub SendEmail
Dim objEmail


' this is actually called to generate an HTML email and insert the
HTML tags
Call GenerateMessage


Set objEmail = CreateObject("CDO.Message")


' these are constants defined at the begining of the script.
' you can also make the TO address a variable if you need to send
different
messages to different recipients.
objEmail.From = FROM_ADDRESS
objEmail.To = TO_ADDRESS
objEmail.Subject = EMAIL_SUBJECT
objEmail.HTMLBody = strEmailBody


' more constants at the top
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") =
SMTP_SENDUSING
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTP_SERVER
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
SMTP_SERVER_PORT
objEmail.Configuration.Fields.Update


objEmail.Send

End Sub

-- end code -->

Where add html tags also?

Thanks,
mistral

From: Bart Perrier on
"mistral" <polychrom(a)softhome.net> wrote in message
news:1170198963.980988.131860(a)p10g2000cwp.googlegroups.com...
> On 30 ���., 23:13, "Bart Perrier" <bart_perr...(a)hotmail.com> wrote:
>> I do this very thing with a number of jobs and have taken advantage of
>> the
>> Message Priority after a long hard battle to figure it out.
>
>> Where you have the wscrpt.echo use a variable instead. Such as
>> strEmailBody = strEmailBody & yourData. If you are using HTML then you
>> will
>> need to add the HTML tags as well.
>
>> Here is the method I call to send email from one particular script. Watch
>> out for the wordwrap.
>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Sub SendEmail
>> Dim objEmail
>
>> ' this is actually called to generate an HTML email and insert the HTML
>> tags
>> Call GenerateMessage
>
>> Set objEmail = CreateObject("CDO.Message")
>
>> ' these are constants defined at the begining of the script.
>> ' you can also make the TO address a variable if you need to send
>> different
>> messages to different recipients.
>> objEmail.From = FROM_ADDRESS
>> objEmail.To = TO_ADDRESS
>> objEmail.CC = CC_ADDRESS
>> objEmail.BCC = BCC_ADDRESS
>> objEmail.Subject = EMAIL_SUBJECT
>> objEmail.HTMLBody = strEmailBody
>
>> ' more constants at the top
>> objEmail.Configuration.Fields.Item
>> ("http://schemas.microsoft.com/cdo/configuration/sendusing") =
>> SMTP_SENDUSING
>> objEmail.Configuration.Fields.Item
>> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
>> SMTP_SERVER
>> objEmail.Configuration.Fields.Item
>> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
>> SMTP_SERVER_PORT
>> objEmail.Configuration.Fields.Update
>
>> objEmail.Send
>
>> End Sub
>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>> Hope this helps.
>> Bart
> --------------------
>
> thanks, Bart. Not fully clear, how to interface mailing code with main
> script.
>
> like this:
>
> <-- start code
> Public Function sGetSomeData()
> ... ... ...
> ... ... ...
> ... ... ...
> sGetSomeData = sSomeData
>
> End Function
>
> else
> wscript.echo strEmailBody = strEmailBody & sGetSomeData
> End If
> End Function
>
> Sub SendEmail
> Dim objEmail
>
>
> ' this is actually called to generate an HTML email and insert the
> HTML tags
> Call GenerateMessage
>
>
> Set objEmail = CreateObject("CDO.Message")
>
>
> ' these are constants defined at the begining of the script.
> ' you can also make the TO address a variable if you need to send
> different
> messages to different recipients.
> objEmail.From = FROM_ADDRESS
> objEmail.To = TO_ADDRESS
> objEmail.Subject = EMAIL_SUBJECT
> objEmail.HTMLBody = strEmailBody
>
>
> ' more constants at the top
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") =
> SMTP_SENDUSING
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> SMTP_SERVER
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
> SMTP_SERVER_PORT
> objEmail.Configuration.Fields.Update
>
>
> objEmail.Send
>
> End Sub
>
> -- end code -->
>
> Where add html tags also?
>
> Thanks,
> mistral
>

Sorry about that, mistral.

Let your results accumulate in a variable such as strEmailBody. Then plug
that variable into the email body.I changed the email format to Text but you
can do it with an HTML email, you just have to add the HTML tags to your
variable (strEmailBody) as you go. It's a little tedious but quite rewarding
=]

Watch out for word wrap.
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim objEmail, strEmailSubject, strEmailBody

Const SEND_USING = "2"
Const SMTP_SERVER = "" ' enter your SMTP server
Const SMTP_PORT = "25"
Const FROM_ADDRESS = "" ' enter your From Address
Const TO_ADDRESS = "" ' enter your To Address

strEmailSubject = "Your Subject"

strEmailBody = strEmailBody & sGetSomeData() & vbCRLF
strEmailBody = strEmailBody & sGetSomeData() & vbCRLF
strEmailBody = strEmailBody & sGetSomeData() & vbCRLF
strEmailBody = strEmailBody & sGetSomeData() & vbCRLF

Set objEmail = CreateObject("CDO.Message")

objEmail.From = FROM_ADDRESS
objEmail.To = TO_ADDRESS
objEmail.Subject = strEmailSubject
objEmail.TextBody = strEmailBody

' more constants at the top
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")
= SEND_USING
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= SMTP_SERVER
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= SMTP_PORT
objEmail.Configuration.Fields.Update

objEmail.Send


Function sGetSomeData()
sGetSomeData = InputBox("Enter Data ", "")
End Function
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


From: mistral on

> > On 30 ñÎ×., 23:13, "Bart Perrier" <bart_perr...(a)hotmail.com> wrote:
> >> I do this very thing with a number of jobs and have taken advantage of
> >> the
> >> Message Priority after a long hard battle to figure it out.
>
> >> Where you have the wscrpt.echo use a variable instead. Such as
> >> strEmailBody = strEmailBody & yourData. If you are using HTML then you
> >> will
> >> need to add the HTML tags as well.
>
> >> Here is the method I call to send email from one particular script. Watch
> >> out for the wordwrap.
>
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> Sub SendEmail
> >> Dim objEmail
>
> >> ' this is actually called to generate an HTML email and insert the HTML
> >> tags
> >> Call GenerateMessage
>
> >> Set objEmail = CreateObject("CDO.Message")
>
> >> ' these are constants defined at the begining of the script.
> >> ' you can also make the TO address a variable if you need to send
> >> different
> >> messages to different recipients.
> >> objEmail.From = FROM_ADDRESS
> >> objEmail.To = TO_ADDRESS
> >> objEmail.CC = CC_ADDRESS
> >> objEmail.BCC = BCC_ADDRESS
> >> objEmail.Subject = EMAIL_SUBJECT
> >> objEmail.HTMLBody = strEmailBody
>
> >> ' more constants at the top
> >> objEmail.Configuration.Fields.Item
> >> ("http://schemas.microsoft.com/cdo/configuration/sendusing") =
> >> SMTP_SENDUSING
> >> objEmail.Configuration.Fields.Item
> >> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> >> SMTP_SERVER
> >> objEmail.Configuration.Fields.Item
> >> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
> >> SMTP_SERVER_PORT
> >> objEmail.Configuration.Fields.Update
>
> >> objEmail.Send
>
> >> End Sub
>
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> >> Hope this helps.
> >> Bart
--------------------

> thanks, Bart. Not fully clear, how to interface mailing code with main
> script.

> like this:

<-- start code
Public Function sGetSomeData()
... ... ...
... ... ...
... ... ...
sGetSomeData = sSomeData
End Function
else
wscript.echo strEmailBody = strEmailBody & sGetSomeData
End If
End Function

Sub SendEmail
Dim objEmail
' this is actually called to generate an HTML email and insert the
HTML tags
Call GenerateMessage
Set objEmail = CreateObject("CDO.Message")
' these are constants defined at the begining of the script.
' you can also make the TO address a variable if you need to send
different
messages to different recipients.
objEmail.From = FROM_ADDRESS
objEmail.To = TO_ADDRESS
objEmail.Subject = EMAIL_SUBJECT
objEmail.HTMLBody = strEmailBody
' more constants at the top
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") =
SMTP_SENDUSING
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTP_SERVER
objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
SMTP_SERVER_PORT
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
-- end code -->

> Where add html tags also?

> Thanks,
> mistral
---------------------------
> Sorry about that, mistral.

> Let your results accumulate in a variable such as strEmailBody. Then plug
> that variable into the email body.I changed the email format to Text but you
> can do it with an HTML email, you just have to add the HTML tags to your
> variable (strEmailBody) as you go. It's a little tedious but quite rewarding
> =]

> Watch out for word wrap.
> ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dim objEmail, strEmailSubject, strEmailBody

> Const SEND_USING = "2"
> Const SMTP_SERVER = "" ' enter your SMTP server
> Const SMTP_PORT = "25"
> Const FROM_ADDRESS = "" ' enter your From Address
> Const TO_ADDRESS = "" ' enter your To Address

> strEmailSubject = "Your Subject"

> strEmailBody = strEmailBody & sGetSomeData() & vbCRLF
> strEmailBody = strEmailBody & sGetSomeData() & vbCRLF
> strEmailBody = strEmailBody & sGetSomeData() & vbCRLF
> strEmailBody = strEmailBody & sGetSomeData() & vbCRLF

> Set objEmail = CreateObject("CDO.Message")
>
> objEmail.From = FROM_ADDRESS
> objEmail.To = TO_ADDRESS
> objEmail.Subject = strEmailSubject
> objEmail.TextBody = strEmailBody

> ' more constants at the top
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")
> = SEND_USING
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
> = SMTP_SERVER
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
> = SMTP_PORT
> objEmail.Configuration.Fields.Update

> objEmail.Send

> Function sGetSomeData()
> sGetSomeData = InputBox("Enter Data ", "")
> End Function
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--------


Hi Bart,

The results of a my code is only one line of digits. So Text format
will be OK. I need that this code just automatically send out this
result on email, without showing any input MsgBox prompt or writing
data to hard drive. I still have problems: I am not sure how to
correctly remove showing input MsgBox prompt and writing data to hard
drive. All that code need to do is automatically send out result by
email.

mistral