There are two controls: TidMessage: IDMSGSEND, TIDSMTP: SMTP
/send email
// Note: The transmitted SMTP property is set by the SMTP_SETUP function.
// Parameters: in: CTO, recipient
// CCC Cc
// CBCC secret
// CSUBJECT theme
// CBODY content
// CattachList sent attachment (with n)
// OUT: MSG Returns Error Message
// Return value 0: Successfully sent
// -1: Failed, see MSG Information
// -2: No SMTP transmission attributes first
INT __FASTCALL TM :: Sendmail (const char * cto, const char * ccc, const char * CBCC,
Const char * csubject, const char * cbody, const char * cattachlist,
Char * cmsg)
{
INT IRET = 0;
IF (! setupok)
Return -2;
IDMSGSEND-> CLEAR (); // clear, otherwise contains the previous information
IDMSGSEND-> ContentType = ContentType;
IDMSGSEND-> from-> text = localmail;
IF (ReturnReciept)
{/ {We set the Recipient to the from e-mail address}
IDMSGSEND-> ReceiptRecipient-> text = idmsgsend-> from-> text;
}
Else
{// {indeicate what there is no receipt recipal}
IDMSGSEND-> ReceipTrecipient-> text = ""
}
IDMSGSEND-> Recipients-> EmailAddresses = CTO; // {to: header}
IDMSGSEND-> SUBJECT = csubject; // {subject: header}
IDMSGSEND-> cclist-> emaildresses = ccc; // {cc}
IDMSGSEND-> bcclist-> emaildresses = cbcc; // {bcc}
IDMSGSEND-> priority = TidMessagePriority (priority); // {message priority}
IDMSGSEND-> Body-> Text = String (CBODY);
IF (Strlen (Cattachlist))
{
Tstringlist * sl = new tstringlist;
SL-> text = string (cattachlist);
For (int i = 0; i
{
IDMSGSEND-> MessageParts-> add ();
New Tidtachment (idmsgsend-> messageparts, sl-> strings [i]);
}
Delete SL;
}
IF (! SMTP-> Connected ())
{
Try
{
SMTP-> Connect ();
Catch (Exception & E)
{
STRCPY (CMSG, "Connection SMTP server failed! Error message:");
STRCAT (CMSG, E.MESSAGE.C_STR ());
IRET = -1;
Return IRet;
}
}
IF (SMTP-> Connected ())
{
Try
{
SMTP-> Send (IDMsgsend);
}
Catch (Exception & E)
{
STRCPY (CMSG, E.MESSAGE.C_STR ());
IRET = -1;
}
}
Else
{
STRCPY (CMSG, "Connecting the SMTP server failed!");
IRET = -1;
}
Return IRet;
}
/ / Set the sent SMTP attribute
// Parameters: in: chOST, SMTP server address
// iPort, SMTP port
// clocalmail sender's mailbox
// iauth is not certified 0, not authenticated, 1 authentication
/ / CUSERNAME Certified User Name
// CPASSWORD authentication password
// OUT: None
// Return value 0: Successful settings
// -1: Failure, missing attributes
INT __FASTCALL TM :: SMTP_SETUP (Const Char * Chost, Const Iport, Const Char * Clocalmail,
Const int iauth, const char * cusername, const char * cpassword)
{
INT IRET = 0;
IF (SMTP-> Connected ())
SMTP-> disconnect ();
SMTP-> Host = String (chOST);
SMTP-> Port = iport;
This-> localmail = string (clocalmail);
Switch (IAuth)
{
// {authentication settings}
Case 0:
SMTP-> AuthenticationType = atnone
Break;
Case 1:
SMTP-> AuthenticationType = atlogin; // {simple login}
Break;
}
SMTP-> Username = CUSERNAME;
SMTP-> Password = CPASSWORD;
Setupok = true;
Return IRet;
}