How to send email using Google SMTP

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Nico1214
Ebase User
Posts: 1
Joined: Tue Jun 16, 2015 3:10 am

How to send email using Google SMTP

#1

Postby Nico1214 » Wed Jun 17, 2015 3:07 am

Hello guys, I am having trouble sending an E-mail through EBase XI. I entered this in my UFS Setup

Code: Select all

Ufs.emailHostId= smtp.gmail.com
I also think i have nothing wrong in my script:

Code: Select all

resources.SUPPORT_EMAIL.sendmail()
I do think there is something missing within my setup since i haven't configured the SMTP Port and TLS and SSL because i don't know where to put those.

So i am receiving this kind of error:
com.ebasetech.xi.exceptions.FormRuntimeException: Mail error sending to email source SUPPORT_EMAIL, 530 5.7.0 Must issue a STARTTLS command first. kk6sm2807844pdb.94 - gsmtp
Can someone help me? Thanks! :roll:
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Wed Jun 17, 2015 7:52 am

You can't configure the email properties at the moment: Ebase will use the default SMTP port 25, also SSL is not supported.
0 x

Ian
Ebase Staff
Posts: 26
Joined: Wed Oct 10, 2007 9:40 am
Location: Ebase HQ
Contact:

#3

Postby Ian » Wed Jun 17, 2015 11:34 am

Hi Niolo,

While Jon is correct in that you cannot configure standard Ebase to use SSL, you can achieve the same thing by writing a script to sent the emails for you (DOES NOT USE AN EBASE EMAIL RESOURCE)

I will email you a working example form and script

The following is the code contained in the script

Code: Select all

importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);

	var _java = JavaImporter(javax.mail, javax.mail.internet, java.util);
/* ---------------------
	Create smtp variables
 ---------------------*/
	var smtpHost = 'smtp.gmail.com';
	var smtpPort = 465;
	var smtpUser = fields.SMTPUSER.value;
	var smtpPassword = fields.SMTPPASSWORD.value;
/* -------------------------
	Populate smtp properities
 -------------------------*/	
	var props = new _java.Properties();
	props.put("mail.smtp.host", smtpHost);
	props.put("mail.smtp.port", smtpPort);
	props.put("mail.smtp.user", smtpUser);
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.socketFactory.port", smtpPort);
	props.put("mail.smtp.socketFactory.class",
	          "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.ssl", "true");
/* --------------------------
	Create a new SMTP session 
 --------------------------*/
	var session = _java.Session.getInstance(props);
/* -----------------------------
	Create the message to be sent
 -----------------------------*/	
	var message = _java.MimeMessage(session);
	message.setFrom(
	    new _java.InternetAddress(fields.FROMEMAIL.value, fields.FROMNAME.value)
	);
	message.setRecipients(
	    _java.Message.RecipientType.TO,
	    [new _java.InternetAddress(fields.TOEMAIL.value, true)]
	);
	message.setText(fields.BODY.value);
	message.setSubject(fields.SUBJECT.value);
	message.setSentDate(new Date());
/* ------------------------------------------------
	Connect to the SMTP session and sent the message
 ------------------------------------------------*/	
	var transport = session.getTransport("smtps");
	transport.connect (smtpHost, smtpPort, smtpUser, smtpPassword);
	transport.sendMessage(message, message.getAllRecipients());
	transport.close();
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#4

Postby Jon » Thu Jun 18, 2015 5:12 pm

The ability to specify any email server property has now been added to Ebase Version 5 - as opposed to the few configurable properties in Version 4. This includes the ability to use TLS or SSL, specify the email port, and configure any other email server property. This makes it possible to use Google mail and any other standard provider out of the box with Email Resources.
0 x


Who is online

Users browsing this forum: No registered users and 18 guests