Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

e-mail my self from a vbs script

Status
Not open for further replies.

Rich75

Technical User
Jun 13, 2003
22
0
0
GB
Hi just wondered if any one can help

i have a backup job that rights out to a text file
i want to automate the notifiction by looking at the text file and picking out the relavent text and then emailing myself with the collected text string


the collection of the data is not a problem but i am a bit stuck on the email part

any ideas

thanks

Rich


 
Here's part of a script that I use to accomplish a similar task. This code uses CDO to send an e-mail with an attachment. You must have Outlook on the system that sends the e-mail.

Regards,

Mapman04

=====

Dim sTo,strLoc,strFname,strSubject,strText,oSession,oMessage,oAttachment,oRecipient

'Sending to home e-mail address

sTo="SMTP:someone@somewhere.com"
strLoc = "X:\Data\DayLog.txt"
strFname = "DayLog.txt"
strSubject = "Nightly Process Check: " & strFname
strText = "The automated audit process was successful!" & vbCr & vbCr & _
"Please review the attached file!" & vbCr & vbCr & _
"This messages was generated by a vbScript at: " & Now() & vbCr & vbCr & "System Admin"
set oSession=CreateObject("MAPI.Session")
oSession.Logon "User"
set oMessage=oSession.Outbox.Messages.Add(strSubject,strText)
set oAttachment=oMessage.Attachments.Add(strFname,,,strLoc)
set oRecipient=oMessage.Recipients.Add(,sTo)
oRecipient.Resolve
oMessage.Send
oSession.Logoff
set oSession=nothing

 
Brilliant thanks for that

however i have a little problem still becuase it is trying to create a new mapi profile i keep on getting the promt on what exchange settings i want to use....


how did you get round this ?
 
I have a valid profile on the PC that the script runs on. Change the "user" to a valid profile name. Outlook does not have to be running. I run it from a NT 4.0 Workstation using Outlook 2000 and my mail server is Exchange 5.5 and I have domain admin rights.

Hope this helps.

Mapman04

 
do you have an smtp server available??

Function smtp(ByVal cTo, ByVal cSubject, ByVal cBody)

Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strSubject
Dim strFrom
Dim strAttachment

set imsg = createobject("cdo.message")
set iconf = createobject("cdo.configuration")

Set Flds = iConf.Fields
With Flds
.Item(" = 2
.Item(" = "smtp.mail.somewhere.com" 'ToDo: Type a valid SMTP server name.
.Update
End With

strHTML = &quot;<HTML>&quot;
strHTML = strHTML & &quot;<HEAD>&quot;
strHTML = strHTML & &quot;<BODY>&quot;
strHTML = strHTML & &quot;<b> &quot; & cSubject & cBody &&quot;</b></br>&quot;
strHTML = strHTML & &quot;</BODY>&quot;
strHTML = strHTML & &quot;</HTML>&quot;
strSubject = &quot;subject&quot;
strFrom = cFrom & &quot;@somwhere.com&quot;



With iMsg
Set .Configuration = iConf
.To = &quot;websms@blaa.com&quot;
.From = &quot;hmm@sm.com&quot;
.Subject = strSubject
.HTMLBody = strHTML
.Send
End With

set imsg = Nothing
set iconf = Nothing

End Function
 
This is outlook using mapi.
Enjoy Bob

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = &quot;name@email.co&quot;
MessageSubject = &quot;Garden Stuff&quot;
MessageBody = &quot;Here are your stuff for 08-22-2003&quot;
MessageAttachment = &quot;Y:\folder\folder\A0005.txt&quot;
Set ol = WScript.CreateObject(&quot;Outlook.Application&quot;)
Set ns = ol.getNamespace(&quot;MAPI&quot;)
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top