Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending email via exchange using proxy. 1

Status
Not open for further replies.

GOSCO

Technical User
Sep 26, 2000
134
GB
Hi I have an off site exchange server that is setup using a http proxy can I amend the following code to send e-mail using this exchange server?

Code:
dim msgTo, msgFrom, sMailServerName, msgTxt, msgAttPath
  
        'set data for msg
        msgTo = "test.mail@domain.com"  'test@qwerty.com"
        msgFrom = "test.mail@domain.com"  '"mail@zxcvbn.com.au"
        msgSubject = "Test message of VBScript"
        msgTxt = "test #1" & vbcrlf & "cdo send"
        msgAttPath = ""
        SendMail msgFrom, msgTo, msgSubject, msgTxt, msgAttPath  

        wscript.quit


Sub SendMail ( sFrom, sTo, sSubject, sBody, sAttachPath)
         
        'allocate variables
        Dim cdoSendUsingPort, cdoAnonymous,cdoDSNSuccessFailOrDelay
        dim objMsg, objConf
        dim tcSubject, lcAttName  
         
        'set constants as VBS doesnt get from Object
        cdoSendUsingPort = 2
        cdoAnonymous = 0
        cdoDSNSuccessFailOrDelay=14
         
        'set server data
        sMailServerName = "exchangeserver"     'exch.qwertyx.com.
         
  
         
         
        Set objConf = CreateObject("CDO.Configuration")
                         
                With objConf.fields
                  .item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = cdoSendUsingPort
                  .item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = sMailServerName
                  .item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")[/URL] = cdoAnonymous 'cdoBasic
                  '.item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername")[/URL] = "test.mail@domain.com"
                  'item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword")[/URL] = "password"
                  .Update
                End With
                 
                Set objMsg = CreateObject("CDO.Message")
                objMsg.Configuration = objConf
          
          
                With objMsg
          
                   
                  .to = sTo
                  .From = sFrom
                  .Subject =  sSubject & " "  
                  .TextBody = sBody
                   'use .HTMLBody to send HTML email.
           
                  if sAttachPath <> "" then
                           .AddAttachment sAttachPath
                  end if
                   
                  .fields("urn:schemas:mailheader:disposition-notification-to") = sFrom
                  .fields("urn:schemas:mailheader:return-receipt-to") = sFrom
          
                  .DSNOptions = cdoDSNSuccessFailOrDelay
                  .fields.Update
                  .Send
                End With
          
                set objConf = Nothing
                Set objMsg = Nothing
END SUB
 
I can use somthing like this to open outlook and send that way though I still need to enter a password for the proxy server if outlook is not already open...

Code:
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0) 'olMailItem
set session = MyApp.getnamespace("mapi")
With MyItem
    .To = "email.domain.com"
    .Subject = "Subject"
    .ReadReceiptRequested = False
    .HTMLBody = "Message<BR>Line 2"
    .send
End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing
[code]
 
Your problem here is that Outlook and CDO are communicating with Exchange in two completely different ways.

Without going into the details, Outlook is talking via Exchange Server protocols (albeit in this case via port 80 through the proxie because you are working against a hosted service)

CDO is talking SMTP - and, in fact, has absolutely no idea that what it is talking to is Exchange Server, nor does it care. All it cares about is that the other end talks SMTP back.

So, what you need is the IP address for the SMTP service on the Exchange Server, which may the IP address pointed at by your MX record.

To find out what that might be, start a command prompt. Type the bold blue stuff. The red bits are just my commentary, and won't appear ...
Code:
C:\>[b][blue]nslookup[/blue][/b]
Default Server:  strongms.dns.com [red](whatever is your default DNS sever will appear here)[/red]
Address:  x.x.x.x

> [b][blue]set type=MX[/blue][/b]
> [b][blue]domain.com[/blue][/b] [red](you enter whatever appears after the @ in your actual email address)[/red]
Server:  strongms.dns.com
Address:  x.x.x.x

Non-authoritative answer:
domain.com      MX preference = 10, mail exchanger = sentry.domainbank.com

sentry.domainbank.com   internet address = 64.85.73.28 [red](Aha! This will be the IP address we want)[/red]
>
So, you'll get something like the above which will provide the IP address you want (there may be more than one, so you'll want the one that matches the MX preference with the lowest value).

CDO should now be able to talk to the SMTP gateway behind that IP address. But that's no guarantee that you'll be able to send the email - for a start, the gateway may not be your Exchange Server (it may be a gateway that then distributes incoming mail to relevant servers), and will almost certainly have relaying disabled. Or it is your Exchange Server, which may also have relaying disabled.

And if relaying is disabled, you won't be able to use CDO to send email to anyone outside your organization (i.e. anyone who isn't on 'domain.com').

You'll need to speak to the hosting company to see what their policy on relaying is, and whether they can enable it just for you.
 
Hi strongm,

Thanks for the assistance. I don't think that will work because I cannot telnet to the IP address on port 25.

Is there any other way I can do this or should I look at vb script that sends through outlook.


 
>because I cannot telnet to the IP address on port 25

In which case all bets are off, and you are indeed limited to sending through Outlook ...
 
Hi thanks in that case I would be looking at using something along the lines of

Code:
session.logon PROFILE, PASSWORD

to add the username password if outlook is not running. I guess the code above won't be expected to work over a http proxy? In which case are there any alternatives?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top