Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Telit Cinterion IoT Developer Community

Sending email

Tutorial, July 16, 2015 - 9:00am, 7011 views

Below an example how to send email using a GMAIL account. The implementation supports socket as well as SSL. In this case SMTP was used only, but the mail class supports receiving and much more.

Using the classes makes it very simple to use SMTP. A few lines of code and the email is sent.

String apn = "m2m.tele2.com";// To be modified, check also if user name

// and password is needed

String mailHost = "smtp.gmail.com"; // To be modified

int mailHostPort = 465;// To be modified

boolean mailHostUsesSSL = true;// To be modified

String mailUser = "xyz@gmail.com"; // To be modified

String mailPass = "password"; // To be modified

String mailReceiver = "any_mailaddress@somehost.com";// To be modified

SmtpClient mailClient = new SmtpClient(null, null);

mailClient.setDebug(true); // optional

try {

// hint: using gmail email address is equal

// user this might be different using other

// mail providers

mailClient.open(mailHost, mailHostPort, mailHostUsesSSL, "GPRS",

apn, null, null, null, null, 30, mailUser, mailPass);

Message msg = new Message(mailUser, mailReceiver, "Test "

+ new Date());

msg.addBodyLine("Hello!\r\nThis is a test\r\nRegards\r\nYour Gemalto Development Forum");

******** env = new ********(msg, true);

mailClient.sendMessage(env);

} catch (IOException e) {

e.printStackTrace();

} catch (MailException e) {

e.printStackTrace();

}

Download File mailExample.zip (zip | 108.82 KB)

I don't use much mails, but I had created my own class to send emails which uses AT commands. But I must say that your example functions much better then my.

Thank you.

Markus this is great thank you. It works just as well if not better than standard AT commands. Well contained module.

I am trying to use this to modify to sending email with attachment. It is from Mail4Me yes, but it seems the MIMEDecoder only interprets the multipart content of incoming email rather than facilitating the build of mail with included attachments.

Have you tried using the API code to send attachment emails? Do you have example using this approach of your?

Many thanks.

N.

Thanks.
Nick.

Author

Markus's picture
Markus