Skip to main content

java code for sending an email

Java code for sending mails. An smtp server is required to relay mails.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="*" %>
<%@page import=""%>
String from = "/** from mail address, eg: */";
String to = "/** to mail address, eg: */";

try {
SmtpClient mailclient = new SmtpClient("/** smtp server, eg: */");
PrintStream message = mailclient.startMessage();
message.println("To: " + to);
message.println("Subject: Lucky Luke");
message.println("finger on a trigger");
} catch (IOException e) {
       out.println("ERROR SENDING EMAIL:" + e);


Popular posts from this blog

Find and replace with sed command in Linux

Find and replace feature is always handy. It can turn into a torture when it comes to change or delete a simple constant string in a text file. There is a handy tool in linux for doing these kind of tihngs. Actually sed is not a text editor but it is used outside of the text file to make changes.