Send java mail throws KM - problems sendMail
Hellow
I implementing the Java send mail post in
send mail throws NoClassDefFoundError: javax/mail/MessagingE
But I have a little problem with the sentence:
<b>sendMailSvc.sendMail(mailItem, iuser);</b>
The stranger is that NetWeaver protests to me that:
<i>The Method sendMail(IResource, IUser) in the type ISendMailService is not applicable for the arguments (ISendMailItems, IUser)</i>
But in the class, NetWeaver showme sendMailSvc.(Ctrl+Space) two Method send mail
1) sendMail(IResource arg0, IUser arg1)
2) sendMail(ISendMailItem arg0, IUser arg1)
Why it does not take the second method? I do not understand
Regards !!
Thanks Detlev for your answer
I import IUser from :
<b>import com.sap.security.api.IUser;</b>
and initialize the variable user :
<b> IWDClientUser user;
IUser iuser = user.getSAPUser();</b>
but you say to me that it would have to use:
<b>import com.sapportals.portal.security.usermanagement.IUser;</b>
how I can initialize the variable "user" for:?
<i>ISendMailItem mailItem = null;
try {
mailItem = sendMailSvc.createMailItem();
mailItem.setContent("Test");
mailItem.setTo("[email protected]");
<b>sendMailSvc.sendMail(mailItem, user);</b></i>
Regards for your help !!!
Similar Messages
-
Urgent ::: Sending java mail from AbstractPortalComponent
Hi all,
I am using WAS SP9 (with EP & KM). I am connecting to corporate exchange server and i am sending mails and i have permission to relay from my server also. The code i used is working fine in webdynpro and also in simple java file but its not working in Abstract Portal Component. Following is the code snippet....
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);//getting error in this line
session.setDebug(sessionDebug);
In the above acode I am getting PRT error when i get instance of session by session.getDefaultInstance method.
I didnt configure anything in the server(like javamail client). Help me out on this...
Thanks in Advance..
Regards
VasuHi Akhilesh,
Thanks for the info. I tried what u told. But,i still have a problem.
String host = "<host ip address>";
boolean sessionDebug = false;
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth","true");
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null); //i am getting the error in this line
session.setDebug(sessionDebug);
Any ideas please?
<b>Regards,
Sai Krishna.</b> -
Program hanged while attempting to send java mail
Java program hanges while atempting to send mail and below is the stack track. Can you please let us know what might using program to hang state.
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
- locked <0xb3b1a680> (a java.io.BufferedInputStream)Thanks, for your response.
Yes its keep on listening state and not getting any data. Also we have set the timeout configuration and still program hangs.
Not throwing any exception. Each time we have to take the jstack trace to check the error before killing the process id. -
Java Mail throws Connect failed error in Oracle 11g Enterprise Edition
Hi,
I am using Oracle 11g Enterprise edition.I have a java class which is used for reading outlook 2010 inbox and download attachments from mails .For Connecting to OutLook from oracle i am using "POP3S" protocol in my java class. Which is working fine until my database is oracle-11g standard edition. Last week we are upgraded our database from oracle 11g standard edition to oracle 11g enterprise edition after that i can't connect to mail server through my java class which throws an error as follows.
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc]
DEBUG POP3: mail.pop3s.rsetbeforequit: false
DEBUG POP3: mail.pop3s.disabletop: false
DEBUG POP3: mail.pop3s.forgettopheaders: false
DEBUG POP3: mail.pop3s.cachewriteto: false
DEBUG POP3: mail.pop3s.filecache.enable: false
DEBUG POP3: mail.pop3s.keepmessagecontent: false
DEBUG POP3: mail.pop3s.starttls.enable: true
DEBUG POP3: mail.pop3s.starttls.required: false
DEBUG POP3: mail.pop3s.apop.enable: false
DEBUG POP3: mail.pop3s.disablecapa: false
DEBUG POP3: connecting to host "194.42.133.180", port 110, isSSL true
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:210)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at GetNoonReport.Connect2Mailserver(GetNoonReport:338)
at GetNoonReport.ReadMail(GetNoonReport:103)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:501)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1038)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:107)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:261)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:206)
... 4 more
Is Oracle Enterprise Edition supports "POP3S" protocol?, Or Enterprise edition needs any additional configuration for establishing outlook connection with "pop3s" ?.
Any help is appreciated
Regards ,
Nisanth907833 wrote:
Hi,
I am using Oracle 11g Enterprise edition.I have a java class which is used for reading outlook 2010 inbox and download attachments from mails .For Connecting to OutLook from oracle i am using "POP3S" protocol in my java class. Which is working fine until my database is oracle-11g standard edition. Last week we are upgraded our database from oracle 11g standard edition to oracle 11g enterprise edition after that i can't connect to mail server through my java class which throws an error as follows.
I suspect root cause is with Java not Oracle.
Oracle RDBMS does NOT speak any "protocol" except SQL natively. -
How to send Java mail with attachment?
Could you please provide the sample codes using the javax.mail api for sending an email with an attachment?
this is code
zareen abbas
<html><body><center>
<FORM ACTION="/servlet/Attach" method="post">
<!--I didn,t used this ENCTYPE-->
<!--ENCTYPE="multipart/form-data" -->
<table border=0 bgcolor background="#00000">
<tr><td><font size=4> <b>From: </b> </font> </td>
<td><input type=text name=from size=40></td></tr>
<tr><td><font size=4> <b>To : </b> </font> </td>
<td><input type=text name=to size=40> </td></tr>
<tr><td><font size=4> <b>CC : </b> </font> </td>
<td><input type=text name=cc size=40> </td></tr>
<tr><td><font size=4> <b>BCC : </b> </font> </td>
<td><input type=text name=bcc size=40> </td></tr>
<tr><td><font size=4> <b>Subject : </b> </font> </td>
<td><input type=text name=subject size=40> </td></tr>
<tr><td><font size=4> <b>Body : </b> </font> </td>
<td><textarea name=body rows=15 cols=40> </textarea> </td></tr>
</table>
<p>Select a file:<input type=file name=attach>
<input type=submit value="send">
<input type=reset name=reset1
value="Clear"></Form></center></body></html>
here the servlet code
File file = new File(filename);
if (file.exists())
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(text);
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
message.setContent(mp);
else
message.setText(text);
Transport.send(message); -
How to send Java Mail with EXCEL attachment?
I tried the following:
ByteArrayDataSource bs = new ByteArrayDataSource (is, "application/excel");
as my datasource (all other apis are fine)
But when I send this message with this datasource as attachment,I get a ParseException with the VM complaining about malformed headers.
Please helpExactly when do you get the ParseException, and what's the message
with the exception?
BTW, "application/excel" is not the correct MIME type for Microsoft Office
Excel files. The correct MIME type is "application/vnd.ms-excel".
http://www.iana.org/assignments/media-types/application/vnd.ms-excel -
Problem sending a mail to many adresses with attachments (Javamail, JSP)
Hi,
i got a problem with JavaMail trying to send a mail to different email-adresses in a JSP. The mail should be send to about 27 adresses, which works fine whenever i send it without any attachments. As soon as i attach a file, the mail still gets send without an error, but only to about 12 adresses instead of the intended 27. I get the adresses out of a database and in either case, there ist the correct amount of adresses. The Mailserver doesnt report anything - it sends the mails without any problem at the 12 adresses.
Here is the part of the code, thats sending:
Properties props = new Properties();
props.put("mail.smtp.host", "192.168.1.1 ");
Session s;
MimeMessage message;
InternetAddress from = new InternetAddress("[email protected]");
InternetAddress to;
s = Session.getInstance(props,null);
Transport trans=s.getTransport("smtp");
//get adresses from db
while (rspartner.next())
to = new InternetAddress(rspartner.getString("postfach"));
message.addRecipient(Message.RecipientType.TO, to);
empfaengerzeile=rspartner.getRow();
//out.println(empfaengerzeile+" --- "+rspartner.getString("postfach")+"<br>");
BodyPart messageBodyPart=new MimeBodyPart();
messageBodyPart.setText(nachricht);
Multipart multipart=new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
//Dateinamen und Speicherort des Plan ermitteln
queryAnhang=dbCon.prepareStatement("select pfad from m_baukoord_kommentar where baukoord_id=? and titel='Entwurfsplan'");
queryAnhang.setString(1,request.getParameter("projektid"));
rsanhang=queryAnhang.executeQuery();
rsanhang.next();
datei=rsanhang.getString("pfad");
//Datei zippen
quellpfad+= ebaukonr.trim() + "/" + datei;
if(datei.contains("."))
zipfilename=datei.substring(0,datei.lastIndexOf('.'))+".zip";
else
zipfilename=datei+".zip";
zielpfad=config.getServletContext().getRealPath("")+"/strasse/UserDownloads/" + zipfilename;
ZipOutputStream zipout = new ZipOutputStream(new FileOutputStream(zielpfad));
zipout.setLevel(9);
zipout.setMethod(ZipOutputStream.DEFLATED);
FileInputStream in = new FileInputStream(quellpfad);
zipout.putNextEntry(new ZipEntry(datei));
int len;
while ((len = in.read(buf)) > 0) {
zipout.write(buf, 0, len);
zipout.closeEntry();
in.close();
zipout.close();
//Datei anhaengen
messageBodyPart = new MimeBodyPart();
FileDataSource source = new FileDataSource(zielpfad);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("Entwurfsplan.zip");
multipart.addBodyPart(messageBodyPart);
message.setSubject("Neues Projekt " + titel + " verfügbar");
message.setContent(multipart);
trans.send(message);With active debug i got following information:
The first mail in the debug-log is with the source code as quoted in my first post, the second mail is when i cut out the part which generates and adds the attachement. I had to make the adresses anonymous, but the second mail contains a lot more adresses then the first, although they both use the same query with same parameters, etc.
Have i done something wrong with the attachements? Overwriting headers, syntax errors, anything? I'm out of ideas...
edit: Had to cut out the debug-log because it is too big. It just said that everything was working ok, but the first mail contains too few adresses and the second (without attachement) the correct number of adresses. I can mail the log, if you like. -
IPhone sending e-mail through OS X Server
I'm running OS X Server 10.6.4 on an xServe. iPhones are having issues sending SMTP e-mail when they're connected to AT&T's cellular network. When I connect an iPhone to a Wi-Fi network it is able to send e-mail with no problems. Here is what appears in the Mail logs on the server.
Sep 16 20:07:13 tim postfix/smtpd[70664]: connect from mobile-166-137-141-102.mycingular.net[166.137.141.102]
Sep 16 20:07:15 tim postfix/smtpd[70664]: lost connection after EHLO from mobile-166-137-141-102.mycingular.net[166.137.141.102]
What am I doing wrong please?Badry,
Sorry, my answer is a little bit late. However, as far as I understand:
1. you want to e-mail a message to a FAX device and have it printed there, and
2. you want to achive this functionality on a Lotus Notes/Domino server, and
3. you want to mail your message using SMTP, and
4. the receipient address should look something like [email protected]
I'm not aware of any 100% pure Java FAX solution doing this. Any solution I've seend so far needs some kind of FAX gateway (e.g. Wingate etc) to convert the message and have it sent as a FAX thru a FAX modem.
If you are using Lotus Notes/Domino it can be done with a Domino based third party FAX gateway software (send a mail to [email protected] if you need more info on this).
This has nothing to do with Java in general, and as far as it concerns the server, the third party software is not platform independent. However, the software supports Domino servers on Windows NT/2000, Unix, Linux, AIX and Sun Solaris (OS/2 up to Notes 4.x only). -
Problem in sending mail using java mail api
This is the pogram I am using as of now to send a mail to yahoo id.
import javax.mail.*;
import javax.mail.internet.*;
public class SendingMail2
public SendingMail2()
try
String from = "ravikiran_sunrays";
String to = "[email protected]";
String subject = "the subject u wanna send ";
String cc="[email protected]";
String bcc="[email protected]";
String text="the matter that u wanna send ";
java.util.Properties prop = System.getProperties();
prop.put("mail.smtp.host","mail.yahoo.com");
//prop.put("http.proxyHost",System.getProperty("http.proxyHost"));
//prop.put("http.proxyPort","8080");
//prop.put("http.proxyPort",System.getProperty("http.proxyPort"));
//prop.put("http.proxyHost","172.19.48.201");
//System.getProperties().setProperty("http.proxyPort","8080");
//System.getProperties().setProperty("http.proxyHost","172.19.48.201");
Session ses = Session.getInstance(prop,null);
MimeMessage message = new MimeMessage(ses);
try
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
message.setSubject(subject);
Address[] toAddress = InternetAddress.parse(to);
Address[] cc_address=InternetAddress.parse(cc);
Address[] bcc_address=InternetAddress.parse(bcc);
message.setRecipients(Message.RecipientType.TO,toAddress);
message.setRecipients(Message.RecipientType.CC,cc_address);
message.setRecipients(Message.RecipientType.BCC,bcc_address);
message.setSentDate(new java.util.Date());
message.setText(text);
Transport.send(message);
System.out.println("Mail Successfully Sent");
catch(Exception e)
System.out.println("Problem " + e);
catch(Exception e)
System.out.println("Problem " + e);
public static void main(String[] args)
SendingMail2 sendingMail2 = new SendingMail2();
This is the exception I am getting when I try 2 execute that program.
avax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Unknown SMTP host: mail.yahoo.com;
nested exception is:
java.net.UnknownHostException: mail.yahoo.comlisten buddy
this is a class i made it is easy to understand it sends mails and check inbox just adduser from telnet with remote manager in james create the three accounts i am using and then use this class and its methods
also the next class that contains the mails test my class and what i am saying
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class MailClient
extends Authenticator
public static final int SHOW_MESSAGES = 1;
public static final int CLEAR_MESSAGES = 2;
public static final int SHOW_AND_CLEAR =
SHOW_MESSAGES + CLEAR_MESSAGES;
protected String from;
protected Session session;
protected PasswordAuthentication authentication;
public MailClient(String user, String host)
this(user, host, false);
public MailClient(String user, String host, boolean debug)
from = user + '@' + host;
authentication = new PasswordAuthentication(user, user);
Properties props = new Properties();
props.put("mail.user", user);
props.put("mail.host", host);
props.put("mail.debug", debug ? "true" : "false");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");
session = Session.getInstance(props, this);
public PasswordAuthentication getPasswordAuthentication()
return authentication;
public void sendMessage(
String to, String subject, String content)
throws MessagingException
System.out.println("SENDING message from " + from + " to " + to);
System.out.println();
MimeMessage msg = new MimeMessage(session);
msg.addRecipients(Message.RecipientType.TO, to);
msg.setSubject(subject);
msg.setText(content);
Transport.send(msg);
public void checkInbox(int mode)
throws MessagingException, IOException
if (mode == 0) return;
boolean show = (mode & SHOW_MESSAGES) > 0;
boolean clear = (mode & CLEAR_MESSAGES) > 0;
String action =
(show ? "Show" : "") +
(show && clear ? " and " : "") +
(clear ? "Clear" : "");
System.out.println(action + " INBOX for " + from);
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
if (msgs.length == 0 && show)
System.out.println("No messages in inbox");
for (int i = 0; i < msgs.length; i++)
MimeMessage msg = (MimeMessage)msgs;
if (show)
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + msg.getContent());
if (clear)
msg.setFlag(Flags.Flag.DELETED, true);
inbox.close(true);
store.close();
System.out.println();
====================================
testing this class
=======================================
public class JamesConfigTest
public static void main(String[] args)
throws Exception
// CREATE CLIENT INSTANCES
MailClient redClient = new MailClient("red", "localhost");
MailClient greenClient = new MailClient("green", "localhost");
MailClient blueClient = new MailClient("blue", "localhost");
// CLEAR EVERYBODY'S INBOX
redClient.checkInbox(MailClient.CLEAR_MESSAGES);
greenClient.checkInbox(MailClient.CLEAR_MESSAGES);
blueClient.checkInbox(MailClient.CLEAR_MESSAGES);
Thread.sleep(500); // Let the server catch up
// SEND A COUPLE OF MESSAGES TO BLUE (FROM RED AND GREEN)
redClient.sendMessage(
"blue@localhost",
"Testing blue from red",
"This is a test message");
greenClient.sendMessage(
"blue@localhost",
"Testing blue from green",
"This is a test message");
Thread.sleep(500); // Let the server catch up
// LIST MESSAGES FOR BLUE (EXPECT MESSAGES FROM RED AND GREEN)
blueClient.checkInbox(MailClient.SHOW_AND_CLEAR);
=======================================================
it suppose to print this
Clear INBOX for red@localhost
Clear INBOX for green@localhost
Clear INBOX for blue@localhost
SENDING message from red@localhost to blue@localhost
SENDING message from green@localhost to blue@localhost
Show and Clear INBOX for blue@localhost
From: green@localhost
Subject: Testing blue from green
Content: This is a test message
From: red@localhost
Subject: Testing blue from red
Content: This is a test message
thanks a lot
but i need ur help plzzzzzzzzzzzz
i can create account from telnet
but how i can create a new account from java .. a jsp page that i made to create a new account on the server
plzzzzzzzz help me
bye -
Problem in sending messages using java mail api
Hi All,
I have a problem in sending messages via java mail api.
MimeMessage message = new MimeMessage(session);
String bodyContent = "ñSunJava";
message.setText (bodyContent,"utf-8");using the above code its not possible for me to send the attachment. if i am using the below code means special characters like ñ gets removed or changed into some other characters.
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);
// Set the email attachment file
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource("C:/sunjava.txt") {
public String getContentType() {
return "application/octet-stream";
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
Transport.send(message);is there any way to send the file attachment with the body message without using MultiPart java class.Taken pretty much straight out of the Javamail examples the following works for me (mail read using Thunderbird) // Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
// Set the 'to' address
for (int i = 0; i < to.length; i++)
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set the 'cc' address
for (int i = 0; i < cc.length; i++)
message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
// Set the 'bcc' address
for (int i = 0; i < bcc.length; i++)
message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
message.setSubject("JavaMail With Attachment");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Here's the file ñSunJava");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
for (int count = 0; count < 5; count++)
String filename = "hello" + count + ".txt";
String fileContent = " ñSunJava - Now is the time for all good men to come to the aid of the party " + count + " \n";
// Create another body part
BodyPart attachementBodyPart = new MimeBodyPart();
// Get the attachment
DataSource source = new StringDataSource(fileContent, filename);
// Set the data handler to this attachment
attachementBodyPart.setDataHandler(new DataHandler(source));
// Set the filename
attachementBodyPart.setFileName(filename);
// Add this part
multipart.addBodyPart(attachementBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message); -
Problems while sending mail using java mail
hi all,
the following are the errors i get while sending a mail from my smtp local host-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
System.out.println("fconn");
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
//Transport.send(msg);
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks..hi all,
the following are the errors i get while sending a mail from my smtp local host-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
else
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
System.out.println("fconn");
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
//Transport.send(msg);
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i dont understand what the problem is..inspite of having the right code..
i guess some firewall problem..
can somebody help me please..il be highly obliged..thanks.. -
Problem with sending mail throgh java mail api
hi folks,
We are having problem regarding sending mail using java mail api.
we are using msgsendsample.java file from demo folder contained in javamail-1.3.3_01 folder.
we are using following command at dos prompt.:
java msgsendsample [email protected] [email protected] smtp.mail.yahoo.com false
It gives following Exception:
--Exception handling in msgsendsample.java
com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for hel
p go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
333) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at msgsendsample.main(msgsendsample.java:93)
** ValidUnsent Addresses
[email protected]
Thanking in Advance...
Please give us guidance to any alternate solution if exists.hi
the smtp server u are using should allow u to send mail to other smtp server like if u r sending mail to yahoo account u have to use yahoo smtp server only .....
bye -
Problems while sending mail using java mail..help...
Hello all,
I am new to Java Mail...
Below is my first program...
Can anybody tell what's wrong in it..??
Thanks in advance....
------------------------------------------------------start--------------------
package test;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Send
public Send()
public void send()
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props=new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.smtp.port","25");
props.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(props,new MyAuthenticator());
session.setDebug(true);
MimeMessage message=new MimeMessage(session);
try
message.setContent("Hello ...","text/plain");
message.setSubject("Test mail...plz don't ignore..");
Address to=new InternetAddress("[email protected]");
Address from=new InternetAddress("[email protected]");
Address replyTo=new InternetAddress("[email protected]");
message.setFrom(from);
message.setReplyTo(new Address[]{replyTo});
message.setRecipient(RecipientType.TO,to);
Transport.send(message);
} catch (AddressException e)
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchProviderException e)
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e)
// TODO Auto-generated catch block
e.printStackTrace();
public static void main(String[] args)
new Send().send();
class MyAuthenticator extends Authenticator
MyAuthenticator()
super();
protected PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication("[email protected]", "*******");
--------------------------------------------end--------------
here is the output.....
DEBUG: setDebug: JavaMail version 1.3.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
220 mx.gmail.com ESMTP 16sm2443823wrl
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
EHLO jijo
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "20971520"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
530 5.7.0 Must issue a STARTTLS command first
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at test.Send.send(Send.java:50)
at test.Send.main(Send.java:68)
QUIT
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at test.Send.send(Send.java:50)
at test.Send.main(Send.java:68)
Can any body help me..??
Thanks and Regards
Jijo vincentHi All,
I am new to javax.mail.
I have attached my code and also error here...
can anyone help to resolve the error?
Code:
public class MailExample {
public static void main(String args[]) {
try {
String host = "localhost"; //args[0];
String from = "[email protected]"; //args[1];
// String to = "[email protected]";//args[2];
String to = "[email protected]";//args[2];
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.starttls.enable","true");
//props.put("mail.smtp.auth","true");
// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(from));
// Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail");
// Send message
Transport.send(message);
catch(AddressException ae){
ae.printStackTrace();
}catch (MessagingException e)
// TODO Auto-generated catch block
e.printStackTrace();
Error:
DEBUG: setDebug: JavaMail version 1.3.3ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
220 localhost
DEBUG SMTP: connected to host "localhost", port: 25
EHLO HDCHCTDAM33726
250-localhost
250 HELP
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 [email protected] Address Okay
RCPT TO:<[email protected]>
250 [email protected] Address Okay
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <10736847.01125315340863.JavaMail.sangeetham@HDCHCTDAM33726>
From: [email protected]
To: [email protected]
Subject: Hello JavaMail
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Welcome to JavaMail
com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)550 Invalid recipient: [email protected]
com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)
QUIT -
Venu : Sending a mail from java proram , getting problem
Hi ,
please go through the below code
Properties ps = new Properties();
ps.put("mail.transport.protocol","smtp");
ps.put("mail.smtp.host","172.20.76.63");
ps.put("mail.smtp.port","25");
Session mailSession = Session.getInstance(ps);
Message msg = new MimeMessage(mailSession);
try
msg.setFrom(new InternetAddress ("Hear Sender Address"));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("hear Receipent Address"));
msg.setSentDate(new Date());
msg.setSubject("Hi From Java Class");
msg.setText("I am sending An Email from Java class ");
Transport.send(msg);
catch(Exception e) { }
by using the above code , is it just possible to send the mail
from only pelple who are in (172.20.76.63) the domain only
while i am trying to send other domain like yahoo , it is showing exception
just suggest me , how to send the mail from any domain to domainHey,
With MIDP it's little bit hard to make application which connects to POP3 or IMAP server because there is no support for socket connections. But if your phone support sockets, it's not hard to
make a simple e-mail client for j2me.
But i've heard that it's possible to make somekind hacked socket connection for MIDP but i'm not sure will that work on actually phones.
- fuse -
How do i send an html page in java mail
hi everyone, i have an problem while sending html page in my java mail application.Actually it's sending the html page correctly but the thing is it doesn't display the gif files . why so ? can anyone help me. i think its b'coz of the path problem.
My requirement is like this :
I would like to send an html page to some [email protected] from my local system . for that i have written one mail application which will build an html page which is also having some gif files. And these gif files are located in my local system. when i sent to some xyz user it's not displaying the gif files . How should i give the path for that gif files. pls help me regarding this. This is Urgent.
Thanx in advance.
by
jjjavachi , here with i have attached my program which will work fine . What u have to do is u have to specify ur smtp host address. from address and to address. And if u want to embedd the gif file u have to specify the gif file name. It will work only in outlook and hotmail. if u have anyother doubt let me know.
import java.io.*;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
import java.sql.*;
import java.text.*;
* @author Jeevan
public class EmbeddingGif {
StringBuffer sb = new StringBuffer();
String line;
public static void main(String[] argv) {
new EmbeddingGif (argv);
public EmbeddingGif (String[] argv) {
String to, subject = null, from = "[email protected]",
cc = null, bcc = null, url = null;
// String mailhost = null;
String mailhost = "10.1.0.106"; // SMTP host address
String mailer = "SendHtmlMail";
String protocol = "imap", host = null, user = "jeevan", password = "jeevan";
String record = "g:/rbs/web-inf/classes/emailstore"; // name of folder in which to record mail
boolean debug = false;
BufferedReader in = null;
int optind;
for (optind = 0; optind < argv.length; optind++) {
if (argv[optind].equals("-T")) {
protocol = argv[++optind];
} else if (argv[optind].equals("-H")) {
host = argv[++optind];
} else if (argv[optind].equals("-U")) {
user = argv[++optind];
} else if (argv[optind].equals("-P")) {
password = argv[++optind];
} else if (argv[optind].equals("-M")) {
mailhost = argv[++optind];
} else if (argv[optind].equals("-f")) {
record = argv[++optind];
} else if (argv[optind].equals("-s")) {
subject = argv[++optind];
} else if (argv[optind].equals("-o")) { // originator
from = argv[++optind];
} else if (argv[optind].equals("-c")) {
cc = argv[++optind];
} else if (argv[optind].equals("-b")) {
bcc = argv[++optind];
} else if (argv[optind].equals("-L")) {
url = argv[++optind];
} else if (argv[optind].equals("-d")) {
debug = true;
} else if (argv[optind].equals("--")) {
optind++;
break;
} else if (argv[optind].startsWith("-")) {
System.out.println(
"Usage: SendHtmlMail [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
System.out.println(
"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
System.out.println(
"\t[-f record-mailbox] [-M transport-host] [-d] [address]");
System.exit(1);
} else {
break;
try {
if (optind < argv.length) {
// XXX - concatenate all remaining arguments
to = argv[optind];
System.out.println("To: " + to);
} else {
System.out.print("To: ");
System.out.flush();
// to = in.readLine();
to = "[email protected]";
if (subject == null) {
System.out.print("Subject: ");
System.out.flush();
// subject = in.readLine();
subject = "New Bill @ " + new Date ();
} else {
System.out.println("Subject: " + subject);
Properties props = System.getProperties();
// XXX - could use Session.getTransport() and Transport.connect()
// XXX - assume we're using SMTP
System.out.println("mailhost :"+mailhost);
System.out.println("from :"+from);
System.out.println("to :"+to);
System.out.println("cc :"+cc);
System.out.println("subject :"+subject);
System.out.println("bcc :"+bcc);
System.out.println("url :"+url);
if (mailhost != null)
props.put("mail.smtp.host", mailhost);
// Get a Session object
Session session = Session.getDefaultInstance (props, null);
if (debug)
session.setDebug (true);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false));
msg.setSubject(subject);
collect(in, msg);
// msg.setHeader("X-Mailer", mailer);
// msg.setSentDate(new Date());
// send the thing off
// Transport.send(msg);
// System.out.println("\nMail was sent successfully.");
} catch (Exception e) {
e.printStackTrace();
public void collect(BufferedReader in, Message msg) throws MessagingException, IOException {
BodyPart bp1=new MimeBodyPart();
String html="<H1>Hello from Jeevan</H1>";
html=html+"<img src=cid:mickey>";
bp1.setContent(html,"text/html");
MimeMultipart mp=new MimeMultipart("related");
mp.setSubType("related");
mp.addBodyPart(bp1);
BodyPart bp2=new MimeBodyPart();
DataSource source=new FileDataSource("fss.gif");
bp2.setDataHandler(new DataHandler(source));
bp2.setHeader("discrete-type","image");
bp2.setHeader("Content-ID","mickey");
mp.addBodyPart(bp2);
msg.setContent(mp);
Transport.send(msg);
System.out.println("\nMail was sent successfully.");
// msg.setDataHandler(new DataHandler( new ByteArrayDataSource(sb.toString(), "text/html")));
Maybe you are looking for
-
Error, while pushing the data from Oracle to MSSQL.
Hi, I am facing the below error, while pushing the data from Oracle to MSSQL. ORA-28500: connection from ORACLE to a non-Oracle system returned this message: [Transparent gateway for MSSQL][Microsoft][ODBC SQL Server Driver][SQL Server]Update or inse
-
Can't access Google 'shopping' search. It pulls up for a quick second then gets replaced by this prompt: (function(){})();(function(){})();
-
I recently purchased a download of Lightroom 6 from B & H Photo for my Macbook Pro . When I attempted to open the download I got the following error message: "Download_Adobe_Photoshop_Lightroom_6_(Mac)" can't be opened because the identity of the d
-
CPU MULTIPIER WILL NOT CHANGE ON K7N2-L
Hi all, I am having problem on changing the cpu multipier on the bios setup. I have tried to lower it, but the Mhz remains the same after the change. I have the lastest bios and I just don't know why. I thought the mobo was able to unlock the cpu
-
hi, I'm currently trying to draw shapes in java for the first time. I've been looking at the tutorials and examples for java.sun but I'm having a few problems. At the moment I have code as follows: public class drawShape{ public void paintComponent(G