Pages

Sunday, 3 July 2011

Send Email using VBScript

VB Script to send email in a structured method

copy the below code to a notepad and save it in yourname.vbs and execute. You will note how to fetch the logged on username info, how to get hostname as well as domain name to a string, in addition to displaying email body fields.

'code starts here KTR----------------------------------
'sending email

Dim objNet
On Error Resume Next

'In case we fail to create object then display our custom error
Set objNet = CreateObject("WScript.NetWork")
If  Err.Number <> 0 Then                'If error occured then display notice
 MsgBox "Don't be Shy." & vbCRLF &_
               "Do not press ""No"" If your browser warns you."
 Document.Location = "UserInfo.html"  
                                        'Place the Name of the document.
                                 'It will display again
End if

Dim strInfo
strInfo =  "" & objNet.UserName + " from the machine " & objNet.ComputerName + " hosted at " & objNet.UserDomain + " Domain."

'MsgBox strInfo --- supress msgbox

'-- can go at last line-- Set objNet = Nothing                    'Destroy the Object to free the Memory


Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = strUserNTName+"Automated: ((Intranet Production Site level Backup Completed Successfully..!!))"
objMessage.From = "
intranetproductionserver@abc.com"
objMessage.To = "
123@abc.com, 456@abc.com"
objMessage.TextBody = "The backup was executed by: " & vbCRLF & _
+ strInfo  & vbCRLF & _
+""& vbCRLF & _
+"Site Level Backup for Intranet Main Site and Subsites: Enforcement, AML, HR & IT completed successfully..!!" & vbCRLF & _
+""& vbCRLF & _
+""& vbCRLF & _
+"Note: " & vbCRLF & _
+"At the time of site level backups all the sites remains locked until processed completely." & vbCRLF & _
+"Site level backup remains at shared location @
\\abc\MOSSBackup\ for 2 days." & vbCRLF & _
+" "& vbCRLF & _
+"Apart from this, daily SQL Content Database (eg.:WSS_Content, WSS_Content_IT, WSS_Content_ENF,..,) backups are automated to NAS storage location @
\\192.168.11.193\backup" & vbCRLF & _
+"These backups are written to Tape Library on a Daily, Weekly and Monthly basis. Monthly backup is finally taken out to the safe locker at ABC Bank." & vbCRLF & _
+" " & vbCRLF & _
+"In addition to the above process, Intranet Site is replicated on a real-time basis to the disaster recovery site at the QDC." & vbCRLF & _
+"" & vbCRLF & _
+"Backup Schedule: " & vbCRLF & _
+"i)   Site Level Backups (using STSADM command): Starts@ 11:20PM, Ends@ 3:20AM" & vbCRLF & _
+"ii)  All Content DB Backup (Back-End Maintenance Plan from SQL): Starts @6PM, Ends@ 11:15PM" & vbCRLF & _
+"iii) DocAve software is used for real-time replication" & vbCRLF & _
+"iv)  Symantec SharePoint Farm level Backup starts at 8PM" & vbCRLF & _
+""& vbCRLF & _
+"File Output Format: " & vbCRLF & _
+"Eg: IntranetBackup_IT_0307Sun.bak, IntranetBackup_ENF_0107Fri.bak, ..," & vbCRLF & _
+"" & vbCRLF & _
+ "Please note that this is an Automated email..! If you have any further concern(s) about the above process, please feel free to drop-in an email to
123@abc.com. I shall get back to you as soon as your email has been prioritized."+"" & vbCRLF & _
+"" +"" & vbCRLF & _
+"-ABC IT Team"
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
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") = "specify your smtp server"
'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
Set objNet = Nothing

'code ends here KTR----------------------------------

DOS command doesnt really allow TELNET command for testing and processing automated emails

No comments:

Post a Comment