0

I want to send an email from my vbscript code, the below code is working properly on my machine, but when I changed my machine, the code is no more able to send email. There were no errors or problems occurred during run, but no emails were sent/delivered. Has anyone else faced a problem like this?

Set objMessage = CreateObject("CDO.Message") 

With objMessage
    .From = SendFrom
    .To   = SendTo
    .Subject  = "Subject"
    .Textbody = ""
    .HTMLBody = "<b>Body</b>"
    With .Configuration.Fields
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing")      = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")     = "SMTP.Gmail.Com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername")   = "Username"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")   = "Password"
        .Update
    End With

    .Send
End With
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Manaysah
  • 375
  • 5
  • 15
  • 29
  • 1
    Can you `telnet smtp.gmail.com 25` from the production machine? If not: what error do you get? – Ansgar Wiechers Feb 18 '13 at 18:21
  • 1
    Doesn't this require both machines to have outlook installed? Could that be the issue? – Andrew Feb 18 '13 at 22:04
  • 1
    @Andrew: No, Outlook is not required. – Ansgar Wiechers Feb 19 '13 at 00:11
  • Ansgar, I had tried telnet smtp of the company company and its work. and the two devices have the outlook installed but with different versions ? does that may a cause of problem ? but I had tried the code on other devices with no outlook and its work. – Manaysah Feb 19 '13 at 06:19
  • I tried to send email from above code but from different script from my machine that send email before, but unfortunately the email not sent, so I think its a script related issue, not to machine – Manaysah Feb 19 '13 at 07:09
  • cAnsgar, there are no errors, the problem just the email not sent – Manaysah Feb 19 '13 at 07:11

3 Answers3

1

I would imagine this is a permissions issue or a firewall issue if it is working on your machine but not the production machine. Carefully look at what is different, is one behind the firewall and other is not?

twaldron
  • 2,722
  • 7
  • 40
  • 55
1

First, since you didn't post the entire code, check that your script doesn't contain a line

On Error Resume Next

If it does: remove the line and try again.

If you don't have that line in your script and the script doesn't raise an error and you can telnet mailserver 25 then it's almost certain that the mail server accepted the mail for delivery and the problem is somewhere upstream. Check the mail server logs.

You can verify if the server actually accepts mail like this:

C:\>telnet mailserver 25
220 mailserver ESMTP
HELO clientname
250 mailserver
MAIL FROM:<joe.average@example.com>
250 2.1.0 Ok
RCPT TO:<joe.average@example.com>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: test

test
.
250 2.0.0 Ok: queued as 4541E2227
QUIT

The line before the QUIT command means that the server accepted the mail. The actual response text may vary depending on which MTA is used, but every MTA will respond with some line like that when it accepts a message.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • thanks Ansgar, this were very helpful and solve the problem as found its related to "On Error Resume Next", – Manaysah Feb 20 '13 at 11:26
0

You need to install CDonts library first. Search on microsoft.com for CDONTS library and install the same.

If you want to send without installation then try the second method. you have to initialize the objects. In that example i remove h in the link because i can't post links

  1. CDO.MESSAGE

    'Script to send an email through QTP nice one Set oMessage = CreateObject("CDO.Message")

    '==This section provides the configuration information for the remote SMTP server. '==Normally you will only change the server name or IP. oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'Name or IP of Remote SMTP Server oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/smtpserver") =""

    'Server port (typically 25) oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    oMessage.Configuration.Fields.Update oMessage.Subject = "Test Mail" oMessage.Sender = "" oMessage.To ="" 'oMessage.CC = "" 'oMessage.BCC = "" oMessage.TextBody = "Test Mail from QTP"&vbcrlf&"Regards,"&vbcrlf&"Test" oMessage.Send

    Set oMessage = Nothing

Krishna
  • 11
  • 4