Send email via SMTP example using .net

Started by Jeff, November 29, 2017, 12:40:32 PM

Previous topic - Next topic

Jeff

Thanks for your help. Is there a WB tutorial for this type of integration into .net. I struggle with the microsoft naming. The OLE stuff as well, but I have always been able to get by because there were some many full examples in the help and tech support board. Thanks All. 
Jeff

td

There are quite a few dotNet examples in the Tech Database but no tutorial.  Dotnet is object-oriented and the naming conventions follow accordingly.  If you lack the background, it may take some practice to master but it isn't all that difficult. The best source of information for Microsoft assemblies is Microsoft's documentation.  It is extensive and has convenient links to the type information for each parameter of a method, method return, or property value.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeff

Ok, back at it. Using the sample below, it seems to work but I am getting the exchange server doesn't support the requested version. I have seem some posts that say I have to declare the exchange server version, but it looks a little greek, do you have any ideas on what I need to change?


Code (winbatch) Select

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Purpose: Send Email Message using Exchange Web Services (EWS)
;;
;; Requiresments:
;;       WinBatch 2013A and newer.
;;       Must be executed by a domain user on a domain computer.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[code=winbatch]cDLL = 'C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1';;; Set to location of the file Microsoft.Exchange.WebServices.dll.
; <'C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1'>.
cUrl = 'https://myserver.mydomain.com/ews/exchange.asmx'
cEmail = 'jeff.eads@mydomain.com';;; Sender email address < guesswho@somedomain.com >.
cPwd   = 'Top$ecret';;; Sender's password < '*topsecret*' >.
cRecp  = 'Jeff@MyOtherEmail.net';;; Send to email address < 'destination@something.com' >.

;ObjectClrOption("version","v4.0.30319")
ObjectClrOption('appbase', cDLL)
ObjectClrOption('useany', 'Microsoft.Exchange.WebServices')

;oEws = ObjectClrNew('Microsoft.Exchange.WebServices.Data.ExchangeService')
;oEws.Credentials = ObjectClrNew('Microsoft.Exchange.WebServices.Data.WebCredentials', cEmail, cPwd)
;oEws.AutodiscoverUrl(cEmail)

oEws = ObjectClrNew('Microsoft.Exchange.WebServices.Data.ExchangeService')
oEws.Credentials = ObjectClrNew('Microsoft.Exchange.WebServices.Data.WebCredentials', cEmail, cPwd)

oEws.Url = ObjectClrNew('System.Uri', cUrl)

oMessage = ObjectClrNew('Microsoft.Exchange.WebServices.Data.EmailMessage', oEws)
oMessage.Subject = 'Test Message'
oBody = ObjectClrNew('Microsoft.Exchange.WebServices.Data.MessageBody')
oBody.Text = 'This message is being sent through EWS with WinBatch CLR hosting'
oMessage.Body = oBody

oMessage.ToRecipients.Add(cRecp)
oMessage.SendAndSaveCopy()
Jeff

td

Consider the following:

Code (winbatch) Select
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; Completely untested!!!!!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;https://msdn.microsoft.com/en-us/microsoft.exchange.webservices.data.exchangeversion?f=255&MSPPError=-2147217396
enumExVer = ObjectCreate('Microsoft.Exchange.WebServices.Data.ExchangeVersion')

; Select one of the following:
;exVersion = enumExver.Exchange2007_SP1
exVersion = enumExver.Exchange2010
;exVersion = enumExver.Exchange2010_SP1
;exVersion = enumExver.Exchange2010_SP2   
;exVersion = enumExver.Exchange2013
;exVersion = enumExver.Exchange2013_SP1   
ExVersion = ObjectClrType('Microsoft.Exchange.WebServices.Data.ExchangeVersion', ExVersion)

objEws = ObjectCreate(' Microsoft.Exchange.WebServices.Data.ExchangeService', ExVersion )
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeff

Thank you! All the ones I have looked has (). Lack of knowledge to convert.
Jeff