Sponsored Content
Top Forums Programming Unable to send email using Java in Linux Post 302967117 by Meghan2525 on Friday 19th of February 2016 01:36:24 PM
Old 02-19-2016
Unable to send email using Java in Linux

Hi All,

We recently moved to Red Hat Enterprise Linux Server release 6.6 from Solaris 10.
The existing Java code to send emails in Solaris is


Code:
public class card_cardMessenger{  	/** 	* Send an e-mail message via the Runtime class 	* @see Runtime 	* @return boolean (success or failure of sending the mail) 	* @param String recipient 	* @param String subject 	* @param String e-mail message 	*/ 	public static boolean sendMessage(String recip, String subj, String msg) { 		try {		 			Runtime rt = Runtime.getRuntime(); 			Process pr = rt.exec("mail -tw " + recip); 		  	OutputStreamWriter out = new OutputStreamWriter(pr.getOutputStream()); 			out.write("Subject: " + subj + "\n"); 			out.write(msg); 			out.flush(); 			out.close(); 			return true; 		} 		catch (Exception e) { 			System.out.println("An exception occurred while sending message: " + e); 			e.printStackTrace(); 			return false; 		} 	}   }

However, the above code doesn't work in Linux - An email is not sent to the mail recipient.
Hence, I modified the mail command in the above code to
Code:
Process pr = rt.exec("mail -s " + recip);

There is one issue with the above code. Now, an email is sent to the mail recipient but the subject line in the email is blank. The subject line appears in the body of the email.

Please let me know the right way to do this. I also read other thread on this site and tried to send an email from the command line using
Code:
mail -s "Some subject line" test@yahoo.com

This works but the same doesn't work from the Java code.

Please help.

Thanks,
Megha
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies

2. Shell Programming and Scripting

unable to send an email attachment

i know its pretty repeated query, but i need to post it in this new thread coz i need it urgently uuencode /var/tmp/chandra/emaillist.txt emaillist.txt | mail -s "message with encoded attachment" am unable to send the attachment emaillist.txt present in the path /var/tmp/chandra/ Is... (11 Replies)
Discussion started by: cmaroju
11 Replies

3. Solaris

Unable to send email to the outside world

Hi all, Iam unable to send mail from my unix machine(solaris x86,version 5.10) to the outside world. I can able to access the internet,but not able to send to any yahoo or company email id. Before posting this,i have searched this forum many times,but could not get the results what i... (5 Replies)
Discussion started by: jayaprakash
5 Replies

4. Solaris

Send an email from Solaris using Linux email server

Hello everyone I have a problem and I need your help: I have a Solaris 10 and Solaris 8 UNIX Servers, and Linux Centos4 as email server. I need send an email from Solaris servers preferably using Centos4 email server. I have no mail service configured in my Solaris computers (1 Reply)
Discussion started by: aflores
1 Replies

5. Linux

Unable to send email with sendmail from PHP 5.3 on CentOS VM

I have a longstanding issue on my CentOS 5.6 VM where I am unable to send email from my PHP application. This is the last bunch of lines from my /var/log/maillog file. Feb 14 10:29:16 dev53 sendmail: s1EATEEo004637: Authentication-Warning: www.craig.dev-crmpicco.lan: apache set sender to... (2 Replies)
Discussion started by: crmpicco
2 Replies

6. UNIX for Advanced & Expert Users

Unable to send the email in formatted way

Legends, I have following entries in /tmp/a.txt file GAP Ric XEOJ181477500.W Flag2 5 Sym XEO1418J775-E msg SEQ_NO:159 db:5 diff 154 process msg GAP Ric XEOJ181400.W Flag2 19 Sym XE418J815-E msg SEQ_NO:101 db:5 diff 96 process msg GAP Ric XEOJ18140.W Flag2 18 Sym XEO18J855-E msg SEQ_NO:88... (21 Replies)
Discussion started by: sdosanjh
21 Replies

7. Shell Programming and Scripting

Shell scripting unable to send the sql query data in table in body of email

I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email. spool table_update.html; SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription'; spool off; exit; Please use code tags next time for your code and data.... (9 Replies)
Discussion started by: Sharanakumar
9 Replies

8. Shell Programming and Scripting

Script to send email if Java process was done

Hi Team, I need script to send notification if java process was down. Can you please help on this. Thanks in adance. Regards, Nagesh (1 Reply)
Discussion started by: Nageswara Reddy
1 Replies

9. Shell Programming and Scripting

Use of java mail to send email from UNIX

Can someone help me to understand how to configure java mail on unix or what is syntex for that to put in script so email can be sent. earlier i was using 'send mail' to send email and not SMPT is stopped in unix machine and they asked us to use java mail. Before I was using this ... (0 Replies)
Discussion started by: mirwasim
0 Replies
deploytool(1m)						    Application Server Utility						    deploytool(1m)

NAME
deploytool - launches the deploytool utility to deploy, package, and edit your J2EE applications SYNOPSIS
deploytool [--help] [--userdir user_directory] [--configdir configuration_directory] Use the deploytool utility to deploy and package your J2EE applications and components, create and edit J2EE deployment descriptors, and create and edit J2EE Application Server specific deployment descriptors. If the application is not J2EE compliant, an error message is dis- played. Only one session of the deploytool utility can run with a specific user directory. A lock file is created to ensure that only one utility session is running. A message is displayed if a lock file is detected. OPTIONS
--help displays the arguments for launching the AssemblyTool. --userdir identifies the user directory. The default user directory is .deploytool under your home directory. Only one deploytool session can be running per user directory. A lock file is created under the user directory to ensure that only one session of the deploytool is running. The deploytool utility uses this directory to store configura- tion information. o On Solaris, the default directory is at ~/.deploytool --configdir identifies the configuration directory. The configuration directory is where the asenv.conf file is located. On Solaris the asenv.conf can be found at: o Bundled installation: /etc/appserver o Unbundled installation: default is /etc/opt/SUNWappserver7 or user specified o Evaluation installation: AS_SERVER_INSTALL/config. Where AS_SERVER_INSTALL is the directory where you have installed the Java 2 Platform, Enterprise Edition 1.4 Application Server Beta 2. EXAMPLES
Example 1: Using deploytool example% deploytool --userdir /myapplication --config_dir /myconfigdir Where --userdir specifies the destination directory, and -config_dir identifies the configuration directory. SEE ALSO
verifier(1M) Sun Java System Application Server March 2004 deploytool(1m)
All times are GMT -4. The time now is 06:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy