Java Code Examples for javax.mail.Message#addHeader()
The following examples show how to use
javax.mail.Message#addHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptAddedFunctions.java From hop with Apache License 2.0 | 4 votes |
public static void sendMail( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
boolean debug = false;
// Arguments:
// String smtp, String from, String recipients[ ], String subject, String message
if ( ArgList.length == 5 ) {
try {
// Set the host smtp address
Properties props = new Properties();
props.put( "mail.smtp.host", ArgList[ 0 ] );
// create some properties and get the default Session
Session session = Session.getDefaultInstance( props, null );
session.setDebug( debug );
// create a message
Message msg = new MimeMessage( session );
// set the from and to address
InternetAddress addressFrom = new InternetAddress( (String) ArgList[ 1 ] );
msg.setFrom( addressFrom );
// Get Recipients
String[] strArrRecipients = ( (String) ArgList[ 2 ] ).split( "," );
InternetAddress[] addressTo = new InternetAddress[ strArrRecipients.length ];
for ( int i = 0; i < strArrRecipients.length; i++ ) {
addressTo[ i ] = new InternetAddress( strArrRecipients[ i ] );
}
msg.setRecipients( Message.RecipientType.TO, addressTo );
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader( "MyHeaderName", "myHeaderValue" );
// Setting the Subject and Content Type
msg.setSubject( (String) ArgList[ 3 ] );
msg.setContent( ArgList[ 4 ], "text/plain" );
Transport.send( msg );
} catch ( Exception e ) {
throw new RuntimeException( "sendMail: " + e.toString() );
}
} else {
throw new RuntimeException( "The function call sendMail requires 5 arguments." );
}
}
Example 2
Source File: ScriptValuesAddedFunctions.java From hop with Apache License 2.0 | 4 votes |
public static void sendMail( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
boolean debug = false;
// Arguments:
// String smtp, String from, String recipients[ ], String subject, String message
if ( ArgList.length == 5 ) {
try {
// Set the host smtp address
Properties props = new Properties();
props.put( "mail.smtp.host", ArgList[ 0 ] );
// create some properties and get the default Session
Session session = Session.getDefaultInstance( props, null );
session.setDebug( debug );
// create a message
Message msg = new MimeMessage( session );
// set the from and to address
InternetAddress addressFrom = new InternetAddress( (String) ArgList[ 1 ] );
msg.setFrom( addressFrom );
// Get Recipients
String[] strArrRecipients = ( (String) ArgList[ 2 ] ).split( "," );
InternetAddress[] addressTo = new InternetAddress[ strArrRecipients.length ];
for ( int i = 0; i < strArrRecipients.length; i++ ) {
addressTo[ i ] = new InternetAddress( strArrRecipients[ i ] );
}
msg.setRecipients( Message.RecipientType.TO, addressTo );
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader( "MyHeaderName", "myHeaderValue" );
// Setting the Subject and Content Type
msg.setSubject( (String) ArgList[ 3 ] );
msg.setContent( ArgList[ 4 ], "text/plain" );
Transport.send( msg );
} catch ( Exception e ) {
throw Context.reportRuntimeError( "sendMail: " + e.toString() );
}
} else {
throw Context.reportRuntimeError( "The function call sendMail requires 5 arguments." );
}
}
Example 3
Source File: ScriptAddedFunctions.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static void sendMail( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
boolean debug = false;
// Arguments:
// String smtp, String from, String recipients[ ], String subject, String message
if ( ArgList.length == 5 ) {
try {
// Set the host smtp address
Properties props = new Properties();
props.put( "mail.smtp.host", ArgList[0] );
// create some properties and get the default Session
Session session = Session.getDefaultInstance( props, null );
session.setDebug( debug );
// create a message
Message msg = new MimeMessage( session );
// set the from and to address
InternetAddress addressFrom = new InternetAddress( (String) ArgList[1] );
msg.setFrom( addressFrom );
// Get Recipients
String[] strArrRecipients = ( (String) ArgList[2] ).split( "," );
InternetAddress[] addressTo = new InternetAddress[strArrRecipients.length];
for ( int i = 0; i < strArrRecipients.length; i++ ) {
addressTo[i] = new InternetAddress( strArrRecipients[i] );
}
msg.setRecipients( Message.RecipientType.TO, addressTo );
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader( "MyHeaderName", "myHeaderValue" );
// Setting the Subject and Content Type
msg.setSubject( (String) ArgList[3] );
msg.setContent( ArgList[4], "text/plain" );
Transport.send( msg );
} catch ( Exception e ) {
throw new RuntimeException( "sendMail: " + e.toString() );
}
} else {
throw new RuntimeException( "The function call sendMail requires 5 arguments." );
}
}
Example 4
Source File: ScriptValuesAddedFunctions.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static void sendMail( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
boolean debug = false;
// Arguments:
// String smtp, String from, String recipients[ ], String subject, String message
if ( ArgList.length == 5 ) {
try {
// Set the host smtp address
Properties props = new Properties();
props.put( "mail.smtp.host", ArgList[0] );
// create some properties and get the default Session
Session session = Session.getDefaultInstance( props, null );
session.setDebug( debug );
// create a message
Message msg = new MimeMessage( session );
// set the from and to address
InternetAddress addressFrom = new InternetAddress( (String) ArgList[1] );
msg.setFrom( addressFrom );
// Get Recipients
String[] strArrRecipients = ( (String) ArgList[2] ).split( "," );
InternetAddress[] addressTo = new InternetAddress[strArrRecipients.length];
for ( int i = 0; i < strArrRecipients.length; i++ ) {
addressTo[i] = new InternetAddress( strArrRecipients[i] );
}
msg.setRecipients( Message.RecipientType.TO, addressTo );
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader( "MyHeaderName", "myHeaderValue" );
// Setting the Subject and Content Type
msg.setSubject( (String) ArgList[3] );
msg.setContent( ArgList[4], "text/plain" );
Transport.send( msg );
} catch ( Exception e ) {
throw Context.reportRuntimeError( "sendMail: " + e.toString() );
}
} else {
throw Context.reportRuntimeError( "The function call sendMail requires 5 arguments." );
}
}