Welcome! Log In


[VBS] Send a simple text mail
copy/paste in a mail.txt file lines below, then rename as mail.vbs and script this: cscript.exe mail.vbs

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = SQL BACKUP PROBLEM"
objMessage.From = "sender@domain.com"
objMessage.To = "receiver@domain.com"
objMessage.TextBody = "SQL BACKUP PROBLEM"
objMessage.Send


with a file attachement:

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "SQL FULL BACKUP PROBLEM"
objMessage.From = "sender@domain.com"
objMessage.To = "receiver@domain.com"
objMessage.Bcc= "copymail@domain.com"
objMessage.TextBody = "I6TM25 - SQL FULL BACKUP PROBLEM"
objMessage.AddAttachment "D:\_SAUVEGARDES-SQL\SQL2008ExpressR2\backupfailed.txt"
objMessage.Send


An other script:


Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "iMacros Message"
objMessage.From = "imacros@test.com"
objMessage.To = "jim@test.com"
objMessage.TextBody = "iMacros script completed. Status = OK"

'==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";) = "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



Edited 2 time(s). Last edit at 02/28/2017 05:34PM by iznogoud.
copy/paste in .VBS

' Constants
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing";
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver";
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport";
Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername";
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword";

' Configuration du mode d'envoi
Const cdoSendUsingPickup = 1 ' Envoi en utilisant un dossier local SMTP pour l'envoi du message
Const cdoSendUsingPort = 2 ' Envoi SMTP direct

' Définit le mode d'authentification
Const cdoAnonymous = 0 ' Anonyme
Const cdoBasic = 1 ' Authentification basique (text clair)
Const cdoNTLM = 2 ' NTLM

' Définit les les valeurs login/mot de passe (à changer donc)
Const smtpUserName = "username"
Const smtpPassword = "password"

' Server et Port à utiliser pour l'envoi
Const smtpServer = "127.0.0.1" ' Changer la valeur par le nom ou l'@ IP du server SMTP
Const smtpServerPort = 25

' Exemple de message à envoyer
Dim sMessage
sMessage = sMessage & "Simple message,<br />"
sMessage = sMessage & "Le but étant simplement de tester l'envoi."

' Création de l'email à envoyer
Set objCDO = CreateObject("CDO.Message")
objCDO.To = "mymail@mydomain.com"
objCDO.From = "destinataire@test.fr"
objCDO.Subject = "Simple test d'envoi d'email"
objCDO.HTMLBody = sMessage

' Mise à jour des champs de configuration, pour l'utilisation du serveur SMTP
objCDO.Configuration.Fields.Item(cdoSendUsingMethod) = cdoSendUsingPort
objCDO.Configuration.Fields.Item(cdoSMTPServer) = smtpServer
objCDO.Configuration.Fields.Item(cdoSMTPServerPort) = smtpServerPort
objCDO.Configuration.Fields.Item(cdoSMTPAuthenticate) = cdoAnonymous ' Utiliser le mode d'authentification approprié, ici avec login/password
objCDO.Configuration.Fields.Item(cdoSendUserName) = smtpUserName
objCDO.Configuration.Fields.Item(cdoSendPassword) = smtpPassword
objCDO.Configuration.Fields.Update

' Envoi de l'email
objCDO.Send
Set objCDO = nothing
Sorry, only registered users may post in this forum.

Click here to login