How to send mail programmatically?

You may have had a need to send mail through code, and you may have seen other blog posts on usage of GSERMES. But starting with v7 and higher because there is no desktop client that code may not work instead you can use ASYRMAIL.ASEND_MAIL API

Before we get to the example, review online help and search for ASYRMAIL.ASEND_MAIL API.

In below example I am adding a button to classic function Sales order, to send an email.

  1. Open Development, Script Dictionary, Windows.
  2. Select OSOH window.
  3. Add a button and Save and Validate.

  4. Validate Sales entry transaction under Setup, Sales, Entry Transaction, Orders.
  5. Open Script editor under Development, Script dictionary, Scripts, Script Editor and add below code.

    Case ACTION
     When "EXEBOUT"    : Gosub BOUTON



    If BOUT="7"  ###### this is the code of our button in Window dictionary
     Local Integer  STA
     Local Integer  TRACE
     Local Char      FIC_TRACE(250)
     Local Char      ISSUERMAIL(250)
     Local Char      A_USER(250)(1..)
     Local Char      CC_USER(250)(1..)
     Local Char      HEADER(250)
     Local Clbfile   BODY(0)
     Local Char      ATTACHMENTS(250)(1..)


     HEADER="The record was read"
     TRACE = 2

     Append BODY , 'This is an email from SOH window button '+chr$(10)
     Append BODY , 'I hope you will enjoy it'+chr$(10)
       If STA <> [V]CST_AOK Then
                    infbox( mess(1163,196,1))
                    infbox( "Ëmail was sent nice!")

  6. Save and compile.
  7. Now open Sales, Orders, Orders.

  8. Click on email button.

Conclusion: You can use ASYRMAIL.ASEND_MAIL API to send email programmatically.