com.alarexgroup.m2mplf.clients
Class SMTPClient

java.lang.Object
  extended by com.alarexgroup.m2mplf.clients.SMTPClient
public class SMTPClient
extends java.lang.Object

Example:

SMTPClient smtp = new SMTPClient("smtp.domain.com",25,connection_profile);
if (smtp.openSMTP("user@domain.com","password")) {
  Logger.logDebug("SMTP OK");
        OutputStream os = smtp.createMessage("user@domain.com","someone@otherdomain.com");
          try {
                  os.write("From: <user@domain.com>\r\nTo: <someone@otherdomain.com>\r\n".getBytes());
                      os.write("Subject: M2M Message\r\n\r\n".getBytes());
                      os.write("Something for message demonstration e.g. Hello!".getBytes());
                      os.flush();
                catch (IOException ex) {
                      ex.printStackTrace();
                }
                 
        if (smtp.sendMessage()) Logger.logDebug("SMTP - message was sent!");
        else Logger.logDebug("SMTP - BAD SEND");
        smtp.closeSMTP();
else Logger.logDebug("SMTP False");

Constructor Summary
SMTPClient(java.lang.String smtpServer, int port, java.lang.String connectionProfile)
          Creates a new instance of SMTPClient (SMTP client)
 
Method Summary
 void closeSMTP()
          Closes this client's SMTP connection
 java.io.OutputStream createMessage(java.lang.String from, java.lang.String to)
           
 boolean openSMTP(java.lang.String user, java.lang.String password)
          Opens SMTP connection in this client
 boolean openSMTPnoAuth()
          Opens an anonymous SMTP conection in this client
 boolean sendMessage()
          Sends the prepared mail message
 boolean sendNOOP()
          Sends a NOOP command to SMTP server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMTPClient

public SMTPClient(java.lang.String smtpServer,
                  int port,
                  java.lang.String connectionProfile)
Creates a new instance of SMTPClient (SMTP client)

Parameters:
smtpServer - server hostname/address
port - server port
connectionProfile - a connection profile to be used
Method Detail

openSMTP

public boolean openSMTP(java.lang.String user,
                        java.lang.String password)
Opens SMTP connection in this client

Parameters:
user -
password -
Returns:
true if succesfully connected

openSMTPnoAuth

public boolean openSMTPnoAuth()
Opens an anonymous SMTP conection in this client

Returns:
true if success

createMessage

public java.io.OutputStream createMessage(java.lang.String from,
                                          java.lang.String to)
Parameters:
from - mail from (e-mail address)
to - mail to (e-mail address)
Returns:
outputstream with prewritten mail headers

sendMessage

public boolean sendMessage()
Sends the prepared mail message

Returns:
true if success

sendNOOP

public boolean sendNOOP()
Sends a NOOP command to SMTP server

Returns:
true if successfully sent

closeSMTP

public void closeSMTP()
Closes this client's SMTP connection