Tech Tip: Sending email using MS Exchange
PRODUCT: 4D Internet Commands | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: December 13, 2012
As of v13.2, 4D Internet Commands is now able to utilize implicit SSL and STARTLS, which is required when sending email using an MS Exchange server.
The following code can be used to send email using an MS Exchange server:
// SMTP_Send $error:=SMTP_New ($smtp_id) $error:=SMTP_Host ($smtp_id;"exchange.domain.com") $error:=SMTP_From ($smtp_id;"username@domain.com") $error:=SMTP_ReplyTo ($smtp_id;"username@domain.com") $error:=SMTP_Subject ($smtp_id;"Message test") $error:=SMTP_Auth ($smtp_id;"domain\\username";"p@ssword") //use valid IDs $Body:="This is a test for messages sent through the Exchange, please do not reply" $error:=IT_SetPort (2;587) //standard STMP mode, port 587 for Exchange $error:=SMTP_To ($smtp_id;"recipient@recipient.com") $error:=SMTP_Body ($smtp_id;$Body) $error:=SMTP_Send ($smtp_id;0) //Send in 'upgradable' mode ALERT(String($error)) |
As you can see in the example code above, the username is prefixed with the domain and separated with an escaped backslash like "domain\\username".
Here is some sample code to send via Exchange using SMTP_QuickSend:
// SMTP_Quicksend $ServerName:="exchange.domain.com" $MsgTo:="recipient@recipient.com" $MsgFrom:="username@domain.com" $Subject:="Test message" $Message:="This is a test for sending a message in secure mode. Please do not reply." $error:=SMTP_QuickSend ($ServerName;$MsgFrom;$MsgTo;$Subject;$Message;0;587;"domain\\username";"p@ssword") ALERT(String($error)) |