Android™
Android™
Send an SMTP NOOP Command
See more SMTP Examples
Demonstrates the Chilkat MailMan.SmtpNoop method, which sends an SMTP NOOP command to the server. NOOP does nothing except elicit a positive response, which is useful for keeping a connection alive or verifying it is still responsive. This example opens an SMTP connection, sends a NOOP, and closes.
Background: When holding an SMTP connection open across many sends (see
OpenSmtpConnection), an idle stretch can cause the server to time out and drop the socket. A periodic NOOP keeps the session active and confirms the server is still responding, so the next SendEmail doesn't fail on a silently-closed connection.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Demonstrates the MailMan.SmtpNoop method, which sends an SMTP NOOP command to the server.
// NOOP does nothing except elicit a positive response, useful for keeping a connection
// alive or verifying it is still responsive.
CkMailMan mailman = new CkMailMan();
// Configure the SMTP server connection.
mailman.put_SmtpHost("smtp.example.com");
mailman.put_SmtpPort(465);
mailman.put_SmtpSsl(true);
mailman.put_SmtpUsername("user@example.com");
mailman.put_SmtpPassword("myPassword");
// Open the SMTP connection.
success = mailman.OpenSmtpConnection();
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
// Send a NOOP to keep the connection alive.
success = mailman.SmtpNoop();
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
success = mailman.CloseSmtpConnection();
if (success == false) {
Log.i(TAG, mailman.lastErrorText());
return;
}
Log.i(TAG, "SMTP NOOP succeeded.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}