Sending email with vbscript

hamza_0081 Posted messages 260 Status Member -  
 ArnaudPia -
Hello,
I want to know how to send an email using a VBS script
Configuration: Windows XP Internet Explorer 6.0

19 answers

zzzer Posted messages 938 Status Member 181
 
Please?
Thank you in advance?

http://www.commentcamarche.net/ccmguide/ccmcharte respect autrui.php3#politesse

--
Don't forget to mark the discussion as resolved as soon as it's the case! -> At the top of the page, Status: Resolved
Also, be careful to respect rule 6 of the charter:
Write messages in clear language without abbreviations, telegraphic style or SMS mode
8
ArnaudPia
 
And the French BAC option is not an option. Tired of having to rewrite everything to understand the question.
0
fafa76
 
Here is an example to send an email in VBS. There are several methods, but I prefer this one because you can manage everything (using variables among other things...). And it works very well for me... :)

With CreateObject("CDO.Message")
.From="toto@gmail.com" // here, it doesn't matter whether the email exists or not
.To="tonDestataire@destinataire.com"
.CC="CopieMail@Copiemail.com" // if you want to add someone in copy
.Subject="test for sending email" // subject of the email
.TextBody="Hello," & Chr(13) & "This is a test " & Chr(13) & "Regards" // your text
// and Chr(13) is used to go to the next line
.AddAttachment("c:\piecejointe.pdf")
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your exchange server for example if you are using outlook: enter the IP"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
On Error Resume Next
.Send
If Err.Number <>0 Then
MsgBox Err.Description,16,"Error"
End If
msgbox "mail sent successfully"
On Error GoTo 0
End With

Hoping this helps you..
Farid T.
5
ftouaimia Posted messages 3 Registration date   Status Member
 
fafa76 = ftouaimia
0
Maxime
 
Thank you very much, it worked for me.
0
petit_gg
 
Great code. It works perfectly on the first try. Thanks for sharing.
0
IMAND Posted messages 1 Registration date   Status Member Last intervention  
 
Cvd we can send emails from any mailbox even if it doesn't belong to us.
0
hamza_0081 Posted messages 260 Status Member 60
 
Thank you very much for the script, but there's an error connecting to the server. I slightly modified your script
[
With CreateObject("CDO.Message")
.From="toto@gmail.com"
.To="hamza0081@gmail.com"
.CC="CopieMail@Copiemail.com"
.Subject="test for sending email"
.TextBody="Hello," & Chr(13) & "This is a test " & Chr(13) & "Best regards"

.AddAttachment("c:\attachment.pdf")
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your Exchange server for example if you use Outlook in your inbox: put the IP here"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
On Error Resume Next
.Send
If Err.Number <>0 Then
MsgBox Err.Description,16,"Error"
End If
msgbox "email successfully sent"
On Error GoTo 0
End With ]

Can you help me again please?
2
fafa76
 
Hello,

I see you haven't responded. I assume you found the solution... at least I hope so for you :)
If your post is still relevant, let me know and I'll help you right away.
Best regards.
1
hamza_0081 Posted messages 260 Status Member 60
 
I want to know how to send an email using a VBS script
Thank you in advance, friends
and I am sorry §§
0
toto
 
it's weird that you don't have a response :p
0
hamza_0081 Posted messages 260 Status Member 60
 
thank you at last someone who understands what I am suffering !!
0
hamza_0081 Posted messages 260 Status Member 60
 
Bonjour, merci pour votre aide. Je tiens à vous informer que je n'ai pas trouvé ce que je cherche.
0
hamza_0081 Posted messages 260 Status Member 60
 
ah ! j'ai oublié de te dire que j'ai créé un fichier c:\piecejointe.pdf
0
fafa76
 
Well, if it works, that's the main thing.
As for the attachment, if you don't need it, delete the corresponding line: this was just an example. It's up to you to adapt it.

If you still need help, just let it be known directly on the forum, don't hesitate... and I will respond if possible...
Farid T
0
hamza_0081 Posted messages 260 Status Member 60
 
It still doesn't work, it displays a message "the transport failed to connect to the server"
and another message says that the message was sent successfully?
When I check my inbox, there are no messages?

[[With CreateObject("CDO.Message")
.From="toto@gmail.com"
.To="hamza0081@gmail.com"
.CC="hamza0081@gmail.com"
.Subject="test for sending email"
.TextBody="Hello," & Chr(13) & "This is a test " & Chr(13) & "Best regards"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "stmp3.google.com"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
On Error Resume Next
.Send
If Err.Number <>0 Then
MsgBox Err.Description,16,"Error"
End If
msgbox "mail sent successfully"
On Error GoTo 0
End With
0
THEMINECRAFT951
 
smtp.gmail.com not stmp.gmail.com
0
ftouaimia Posted messages 3 Registration date   Status Member
 
Are you sure about your SMTP address (Google)?

Otherwise, I’ll check it later

Farid
0
hamza_0081 Posted messages 260 Status Member 60
 
To obtain this address, I did
1. launch cmd
2. type nslookup
3. type set q=mx
4. type google.com
and the result is
[[
> set q=mx
> google.com

Non-authoritative answer:
google.com MX preference = 10, mail exchanger = smtp2.google.com
google.com MX preference = 10, mail exchanger = smtp3.google.com
google.com MX preference = 10, mail exchanger = smtp4.google.com
google.com MX preference = 10, mail exchanger = smtp1.google.com

google.com nameserver = ns4.google.com
google.com nameserver = ns1.google.com
google.com nameserver = ns2.google.com
google.com nameserver = ns3.google.com
smtp1.google.com internet address = 209.85.237.25
smtp2.google.com internet address = 64.233.165.25
smtp3.google.com internet address = 64.233.183.25
smtp4.google.com internet address = 72.14.221.25
ns1.google.com internet address = 216.239.32.10
ns2.google.com internet address = 216.239.34.10
ns3.google.com internet address = 216.239.36.10
ns4.google.com internet address = 216.239.38.10
> google.com>>googl.txt
Unrecognized command: google.com>>googl.txt
>

]]

I learned this method on the internet to know the server and then to send emails
via cmd with the command telnet smtp3.google.com 25

today it no longer works on Google.
0
hamza_0081 Posted messages 260 Status Member 60
 
In short, I'm not sure? I think I made a mistake somewhere :-(
0
hamza_0081 Posted messages 260 Status Member 60
 
before I used the smtp183.google.com server
0
ftouaimia Posted messages 3 Registration date   Status Member
 
Anyway, the SMTP server for Google is stmp.gmail.com
I have to leave but I'll check this tomorrow

Have a good evening
0
hamza_0081 Posted messages 260 Status Member 60
 
Ok! Thanks for everything, I'm going to try the server!
Good evening, bye :-)
0
hamza_0081 Posted messages 260 Status Member 60
 
With CreateObject("CDO.Message")
.From="toto@gmail.com"
.To="hamza_0081@commentcamarche.com"
.Subject="test for sending email"
.TextBody="Hello," & Chr(13) & "This is a test " & Chr(13) & "Best regards"

.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "raoul.commentcamarche.org"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
On Error Resume Next
.Send
If Err.Number <>0 Then
MsgBox Err.Description,16,"Error"
End If
msgbox "email sent successfully"
On Error GoTo 0
End With
0
hamza_0081 Posted messages 260 Status Member 60
 
Good evening, I’m using this script and it seems to work very well, but I’m not receiving any messages?

With CreateObject("CDO.Message")
.From="hamza_0081@commentcamarche.com"
.To="hamza_0081@commentcamarche.com"
.Subject="Test for sending email"
.TextBody="Hello," & Chr(13) & "This is a test " & Chr(13) & "Sincerely"

.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "raoul.commentcamarche.org"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
On Error Resume Next
.Send
If Err.Number <>0 Then
MsgBox Err.Description,16,"Error"
End If
msgbox "Email sent successfully"
On Error GoTo 0
End With
0