Sending email with vbscript
hamza_0081
Posted messages
260
Status
Member
-
ArnaudPia -
ArnaudPia -
Hello,
I want to know how to send an email using a VBS script
I want to know how to send an email using a VBS script
Configuration: Windows XP Internet Explorer 6.0
19 answers
-
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
-
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. -
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? -
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. -
I want to know how to send an email using a VBS script
Thank you in advance, friends
and I am sorry §§ -
-
thank you at last someone who understands what I am suffering !!
-
Bonjour, merci pour votre aide. Je tiens à vous informer que je n'ai pas trouvé ce que je cherche.
-
ah ! j'ai oublié de te dire que j'ai créé un fichier c:\piecejointe.pdf
-
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 -
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 -
Are you sure about your SMTP address (Google)?
Otherwise, I’ll check it later
Farid -
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. -
In short, I'm not sure? I think I made a mistake somewhere :-(
-
-
Anyway, the SMTP server for Google is stmp.gmail.com
I have to leave but I'll check this tomorrow
Have a good evening -
Ok! Thanks for everything, I'm going to try the server!
Good evening, bye :-) -
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 -
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