Specify a SMTP server to send mail to via VBS

LoG
LoG used Ask the Experts™
on
I need your help to create an email generation VBscript.  In this script, I will be parsing a text document for information to include in the body of the outgoing emails.  Parsing the text document will be very straight forward, but the problem comes when I need to generate the email message.  I do not have an in-house mail or IIS server available.  So, I need to find out how to use VBS to send an email message to a specified mail server (either by IP or DNS name).  To connect to this mail server I will have to pass credentials so that they do not think I am trying to relay.  Anyone here that knows how to do this?

To recap, the solution must:  
Work under VBscript (possibly WSH)
Send credentials to an outside ISP SMTP server
Send the email to this mail server
Require no third party software
Run without ASP

The reward, 200 points!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Take a look at CDO and CDONTS components included with Windows. You will find a lot of examples. Even on Experts Exchange: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11016941.html
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

This is what I've used in the past in VB.  I don't know about the credentials piece, it has always sent for me without a problem though.

   
    Const sBodyCRLF As String = "%0d%0a"
    sEMails = "somebody@somemailaddress.com"
   
    sEmailText = "Email Text"
       
    sEmailText = sEmailText & sBodyCRLF & "Another Line of Email Text"
   
    sSubjectLine = "My SubjectLine"
       
   
    Call SendMail(sEMails, "", "", sSubjectLine, sEmailText)
   

Sub SendMail(ByVal strAddress As String, _
Optional ByVal strCC As String, _
Optional ByVal strBCC As String, _
Optional ByVal strSubject As String, _
Optional ByVal strBodyText As String)
    Dim strTemp As String
   
    If Trim(Len(strCC)) Then
    strTemp = "&CC=" & strCC
    End If
   
    If Trim(Len(strBCC)) Then
    strTemp = strTemp & "&BCC=" & strBCC
    End If
   
    If Trim(Len(strSubject)) Then
    strTemp = strTemp & "&Subject=" & strSubject
    End If
   
    If Trim(Len(strBodyText)) Then
    strTemp = strTemp & "&Body=" & strBodyText
    End If
   
    If Len(strTemp) Then
    Mid(strTemp, 1, 1) = "?"
    End If
   
    strTemp = "mailto:" & strAddress & strTemp
   
    ShellExecute 0, "open", strTemp, 0, 0, SW_NORMAL
   
End Sub
LoG

Author

Commented:
I am sure this code works just fine for VB, but this script will not be compiled...  Thus the mystery of how this will work...  This must be a VBS or WSH script that will work on any PC Win98 or higher.

I guess I should also clarify that there is currently no mail client being used on this PC.  So, this needs to send a basic SMTP message directly to an SMTP server at the ISP.  In order for the email to go through this server, the script must pass login credentials so that the server does not think this is a relay script (it is not).

If you would like to propose a solution using a MAPI mail program as the sending agent, I will consider that for a solution if it is all done in a script as mentioned above.

(This is not a simple task from what I have tried so far)
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

LoG

Author

Commented:
I am sure this code works just fine for VB, but this script will not be compiled...  Thus the mystery of how this will work...  This must be a VBS or WSH script that will work on any PC Win98 or higher.

I guess I should also clarify that there is currently no mail client being used on this PC.  So, this needs to send a basic SMTP message directly to an SMTP server at the ISP.  In order for the email to go through this server, the script must pass login credentials so that the server does not think this is a relay script (it is not).

If you would like to propose a solution using a MAPI mail program as the sending agent, I will consider that for a solution if it is all done in a script as mentioned above.

(This is not a simple task from what I have tried so far)
LoG

Author

Commented:
I am sure this code works just fine for VB, but this script will not be compiled...  Thus the mystery of how this will work...  This must be a VBS or WSH script that will work on any PC Win98 or higher.

I guess I should also clarify that there is currently no mail client being used on this PC.  So, this needs to send a basic SMTP message directly to an SMTP server at the ISP.  In order for the email to go through this server, the script must pass login credentials so that the server does not think this is a relay script (it is not).

If you would like to propose a solution using a MAPI mail program as the sending agent, I will consider that for a solution if it is all done in a script as mentioned above.

(This is not a simple task from what I have tried so far)
The only compiled portion of this is in the ShellExecute which is inthe Windows API, not my code.  As long as VBScript can declare APIs, all should be well.  My example should be easy enough to transfer to VBScript. It is only the setting of variables, and then calling an API.  You can even remove the subroutine call and dump it directly into the main script.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- answered by twalgrave
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

twalgrave
Cleanup Volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Commented:
Is it possibel to send me a code to use the MAPI Client or outlook express to send the mail alert. Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial