sendMail()

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

Synopsis

void sendMail(string smtp_host, dyn_string email, int & ret, string smtp_user = "", string smtp_pass = "", bool useTLS = FALSE, string sAttachPath = "");

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>
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).

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