sendMail()

The sendMail() function sends encrypted e-mails using an SMTP server.

Synopsis

void sendMail(string smtp_host, anytype email, int &ret, string smtp_user = "", string smtp_pass = "", bool useTLS = FALSE, string sAttachPath = "", bool verbose = false)

Parameters

Parameter Description
smtp_host The name or address of the SMTP server.
email (dyn_string)

The email parameter must include the following information:

  • email[1]: <destination e-mail address>
  • email[2]: <sender e-mail address>
  • email[3]: <subject>
  • email[4]: <body>
  • email[5]: <CC e-mail addresses>
  • email[6]: <BCC e-mail addresses>
email (mapping)

The email mapping must include these required keys:

  • subject (string): The e-mail subject.
  • from (string|dyn_string): The sender's e-mail address.
  • to (string|dyn_string): The recipient's e-mail address.
  • body (string): The e-mail content.

Optional keys:

  • cc (string|dyn_string): CC e-mail addresses (same as previous email[5]).
  • bcc (string|dyn_string): BCC e-mail addresses (same as previous email[6]).
  • username (string): SMTP server user name (same as previous smtp_user).
  • password (string): SMTP server password (same as previous smtp_pass).
  • tls (bool): Set to TRUE to enable encryption and authentication (SSL/TLS) (same as previous useTLS).
  • attachment (string|dyn_string): Full path(s) for attachments (similar to previous sAttachPath, but allows multiple attachments).
  • verbose (bool): Enables verbose output and can be used to receive additional details.
  • bodyType (string): Specifies the body format:
    • auto (default)
    • html
    • text
  • verifyHost (bool): If true, verifies the server host name (default: false).
ret Variable to store error codes that occur when sending or receiving e-mails, such as failed delivery or a full mailbox.
smtp_user User name for the SMTP server.
smtp_pass Password for the SMTP server.
useTLS Set to TRUE to enable encryption and authentication (SSL/TLS).
sAttachPath Full path to the attachment file(s).
verbose Enables verbose output and can be used to receive additional details.

Return value

This function does not return a value.

Errors

Possible errors include failure to send the e-mail, a full mailbox, or inability to connect to the SMTP server.

Details

To use sendMail(), you must add a reference to the communication library:

#uses "communication"
Note:
This function is implemented as a Qt program and uses the cutelyst/simple-mail libraries.

This example sends an e-mail with the subject "Hello" and the body "Hi this is a Test" to maxMustermann@googlemail.com.

#uses "std.ctl"
#uses "communication"

main()
{
  string smtp_host = "smtp.gmail.com:587";
  dyn_string email;
  email = makeDynString ("maxMustermann@googlemail.com", "maxMustermann@etm.at", "Test Mail","Hi, this is a Test and a copy of the mail will also be sent to Marie!", "marie.musterfrau@gmail.com");
  int ret;
  string smtp_user = "maxMustermann@googlemail.com";
  string smtp_pass = "myPassword";
  bool useTLS = TRUE;
  string sAttachPath  = "D:\\Downloads\\Image1.png";
  sendMail(smtp_host, email, ret, smtp_user, smtp_pass, useTLS, sAttachPath);
}

Assignment

Communication Functions

Availability

UI, CTRL