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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send email using vb

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
I want to be able to send an email using a vb file, fill in the email address (or grab using AD if that is possible) to send to user the first time they log onto their machine.

The admin at work say they can add a file to be exectuted to the login command so I guess I need a .vbs file that can send the email.

It is a welcome to our company email (we used to use message.msg to do this but IT upgraded to Outlook 2003 and this facility has now been removed).

Can someone point me to a site or recommend somewhere that will show me how to do send email with vb? I read somewhere that I can user server variables to grab the NT account username which is the same as their email address to send to.

Thank you
 
Below is a .vbs file that sends an email with an attachment.
The file is really a text file with a .vbs extension generated in a program that uses tables for email address and file names for attachments but the basic vbs code is there using MAPI.
Hope this helps ~~Bob~~

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "SOMEONE@EMAIL.COM"
MessageSubject = "SOME SUBJECT HERE"
MessageBody = "Here IS YOUR FILE"
MessageAttachment = "Y:\FOLDER\SUBFOLDER\SOMEFILE.TXT"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
SET OL = NOTHING
SET NS = NOTHING
SET NEWMAIL = NOTHING

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top