Author Topic: Send email via SMTP example using .net  (Read 1183 times)

Jeff

  • Newbie
  • *
  • Posts: 19
Re: Send email via SMTP example using .net
« Reply #35 on: February 05, 2018, 09:07:23 am »
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

  • Tech Support
  • *****
  • Posts: 2349
    • WinBatch
Re: Send email via SMTP example using .net
« Reply #36 on: February 05, 2018, 10:45:02 am »
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.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


Jeff

  • Newbie
  • *
  • Posts: 19
Re: Send email via SMTP example using .net
« Reply #37 on: February 08, 2018, 11:52:35 am »
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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

  • Tech Support
  • *****
  • Posts: 2349
    • WinBatch
Re: Send email via SMTP example using .net
« Reply #38 on: February 08, 2018, 01:53:22 pm »
Consider the following:

Code: Winbatch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; 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 )
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


Jeff

  • Newbie
  • *
  • Posts: 19
Re: Send email via SMTP example using .net
« Reply #39 on: February 08, 2018, 01:55:16 pm »
Thank you! All the ones I have looked has (). Lack of knowledge to convert.
Jeff