SMTP: Difference between revisions

598 bytes added ,  23 February 2019
m
add syntax highlighting
(Changing How To/Cookbook -> Tutorials)
m (add syntax highlighting)
 
(3 intermediate revisions by 2 users not shown)
Line 41: Line 41:
# Add the following object to the top of the view, anywhere inside or outside of the view itself:
# Add the following object to the top of the view, anywhere inside or outside of the view itself:


<source lang="dataflex">
     Object oComMailSender is a cComMailSender
     Object oComMailSender is a cComMailSender
     End_Object
     End_Object
 
</source>
And then we need to create the object.
And then we need to create the object.


<source lang="dataflex">
     Send CreateComObject to oComMailSender
     Send CreateComObject to oComMailSender
</source>


The COM object must be created prior to it’s being used.  One of the common problems is once the code is complete you get an error about the object being activated before it’s instantiated.  Add the create statement just below the object declaration.
The COM object must be created prior to it’s being used.  One of the common problems is once the code is complete you get an error about the object being activated before it’s instantiated.  Add the create statement just below the object declaration.
Line 52: Line 55:
In aspemail.pkg at the bottom in class cComMailSender you will find a line as follows:
In aspemail.pkg at the bottom in class cComMailSender you will find a line as follows:


<source lang="dataflex">
   Set peAutoCreate to acNoAutoCreate
   Set peAutoCreate to acNoAutoCreate
</source>


When an [[ActiveX]] component is created, this is set to AutoCreate, but when a COM Automation component is created, it’s set to NoAutoCreate.  This could be changed in aspemail.pkg or simply add the line as shown above.  
When an [[ActiveX]] component is created, this is set to AutoCreate, but when a COM Automation component is created, it’s set to NoAutoCreate.  This could be changed in aspemail.pkg or simply add the line as shown above.


===Sending the email===
===Sending the email===
Line 60: Line 65:
Inside the [[OnClick]] event in the ''Send'' button added above, add the following code:
Inside the [[OnClick]] event in the ''Send'' button added above, add the following code:


<source lang="dataflex">
   String sAttach sName
   String sAttach sName
   Integer iRC
   Integer iRC
Line 85: Line 91:
              
              
   Get ComSend of oComMailSender "" to iRC
   Get ComSend of oComMailSender "" to iRC
   If (not(iRC)) send stop_Box "Email failed."  
   If (not(iRC)) send stop_Box "Email failed."
 
  // Alternative login - if using the free non-pro version
  // the ComUserName and ComPassword properties will not work
  // use this instead:
  Send ComLogonUser of oComMailSender "" "YourEmailLoginID" "YourEmailLoginPassword" 0
</source>


===SMTP Host===
===SMTP Host===
Line 106: Line 118:


Look in the aspemail.pkg and you will see a large list of functions and procedures that may be used with this dll.  Remove the ''com'' from the front of the method name and the remaining name is the one that is used in the aspemail manual, so figuring out how things work is relatively easy.
Look in the aspemail.pkg and you will see a large list of functions and procedures that may be used with this dll.  Remove the ''com'' from the front of the method name and the remaining name is the one that is used in the aspemail manual, so figuring out how things work is relatively easy.
One consideration is that aspemail, while an excellent product, will not work with SSL so email providers like gmail can't easily be used for the SMTP server.  If SSL isn't a consideration, then this would be an excellent choice.


[[Category: ActiveX]]
[[Category: ActiveX]]
[[Category: Tutorials]]
[[Category: Tutorials]]