KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using 4DIC 12.1 to send email via Gmail
PRODUCT: 4D Internet Commands | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: December 17, 2010

The following sample code will allow you to send email via Gmail's STMP host when using 4D v12.1 with the 4D Internet Commands v12.1 plug-in installed:

C_INTEGER($error;$sslSMTPPort)
C_LONGINT($smtp_id)
C_TEXT($smtpHost)
C_TEXT($gmailUser;$gmailPass;$replyTo;$sendEmailTo)
C_TEXT($msg;$subject)

$sslSMTPPort:=465 // port used for SSL SMTP - gmail wants 465
$smtpHost:="smtp.gmail.com" // smtp host for gmail
$gmailUser:="me@gmail.com" // gmail user
$gmailPass:="mySuperSecretPassword" // gmail password

$replyTo:="me@gmail.com" // have replies sent here
$sendEmailTo:="someoneelse@somewhere.com" // send email here

$subject:="put subject here" // subject for email
$msg:="This is the message body." // email body

$error:=IT_SetPort (12;$sslSMTPPort) //12 is for 'SMTP with SSL'

$error:=SMTP_New ($smtp_id)
$error:=SMTP_Host ($smtp_id;$smtpHost;0)
$error:=SMTP_Auth ($smtp_id;$gmailUser;$gmailPass;0)
SMTP_AddHeader ($smtp_id;"Importance";"Normal";0)
$error:=SMTP_From ($smtp_id;$gmailUser;1)
$error:=SMTP_ReplyTo ($smtp_id;$replyTo;0)
$error:=SMTP_To ($smtp_id;$sendEmailTo;0)
$error:=SMTP_Subject ($smtp_id;$subject;0)
$error:=SMTP_Body ($smtp_id;$msg;0)
$error:=SMTP_Send ($smtp_id;1) //1 to use ssl


Simply modify the variables at the top of the sample code and you should be Gmail'ing with ssl in no time!

Commented by David Nasralla on August 10, 2013 at 3:10 AM
I think it is important to note that you can't specify a custom return address in gmail when using a gmail smtp server. For example, if the authenticating user name is:bsmith@company.comAnd you specify a return address of:"Alfred Newman" Gmail will rewrite the return address as:"Alfred Newman"