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 John Tel 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 exhange using VB.net

Status
Not open for further replies.

GOSCO

Technical User
Sep 26, 2000
134
GB
We have an offsite exchange server (not managed by us) and im trying to write a VB script that sends email's using this exchange server.

I've seen a few VB and PHP examples that do just this however the exchange server we connect to is setup using a I must admit I don't understand how this work but needless to see the Microsoft exchange server field does not resolve to an IP adress, whicn means none of the scripts seem applicable as they all ask for a smtp server.

Ive written a VB script that interacts with outlook though this seems clunky and I wanted to look into a better way to do this.

Does anyone have any advice, examples or info that might help me to be able to send emails this way :)

Thanks in advance! Please let me know if im missing or you need any more info.
 

Could you post your code?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
This is the code I found that would work with a "normal" exchange server on a network. It seems our exchange server connects through a proxy, which is a slight complication.


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
 
Sorry yes though equally I would be happy to do this using VB.net!

Ive looked into using System.Net.Mail though it appears this will not support use of a proxy address...

Is there anybody that has VB.net example code that can send email via a proxy server?

Ill post on the VBscript forum as well to see if anyone can help.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top