Sending email with vbscript

Hello,
I want to know how to send an email using a VBS script
Configuration: Windows XP Internet Explorer 6.0

19 answers

  1. 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
    1. And the French BAC option is not an option. Tired of having to rewrite everything to understand the question.
  2. 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
    1. 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
      1. Ok! Thanks for everything, I'm going to try the server!
        Good evening, bye :-)
        1. Anyway, the SMTP server for Google is stmp.gmail.com
          I have to leave but I'll check this tomorrow

          Have a good evening
          1. In short, I'm not sure? I think I made a mistake somewhere :-(
            1. 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.
              1. Are you sure about your SMTP address (Google)?

                Otherwise, I’ll check it later

                Farid
                1. 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
                  1. smtp.gmail.com not stmp.gmail.com
                2. 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
                  1. ah ! j'ai oublié de te dire que j'ai créé un fichier c:\piecejointe.pdf
                    1. 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?
                      1. 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.
                        1. fafa76 = ftouaimia
                        2. Thank you very much, it worked for me.
                        3. Great code. It works perfectly on the first try. Thanks for sharing.
                        4. Cvd we can send emails from any mailbox even if it doesn't belong to us.
                      2. Bonjour, merci pour votre aide. Je tiens à vous informer que je n'ai pas trouvé ce que je cherche.
                        1. 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. thank you at last someone who understands what I am suffering !!
                            1. I want to know how to send an email using a VBS script
                              Thank you in advance, friends
                              and I am sorry §§