Академический Документы
Профессиональный Документы
Культура Документы
Here's my code:
import javax.mail.*;
import javax.mail.event.TransportListener;
import javax.mail.event.TransportEvent;
import javax.mail.internet.*;
import java.util.Properties;
import javax.activation.*;
class MailSender {
MailSender()
{
//Creating a Session
props=new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", mailHost);
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
try
message=new MimeMessage(mailSession);
mailBody=new MimeMultipart();
message.setFrom(sender);
message.setRecipients(Message.RecipientType.TO, toList);
body="Hello!";
mainBody=new MimeBodyPart();
mainBody.setDataHandler(new DataHandler(body, "text/plain"));
mailBody.addBodyPart(mainBody);
fds=new FileDataSource(myFile);
mimeAttach=new MimeBodyPart();
mimeAttach.setDataHandler(new DataHandler(fds));
mimeAttach.setFileName(fds.getName());
mailBody.addBodyPart(mimeAttach);
message.setContent(mailBody);
Transport.send(message);
catch(java.io.UnsupportedEncodingException e)
System.out.println(e);
catch(MessagingException e)
System.out.println(e);
catch(IllegalStateException e)
System.out.println(e);
}
}
new MailSender();
MyAuthenticator()
super();
}
Keywords & Tags: smtpsendfailedexception, 530, 5.7.0, issue, starttls, command, first,
enterprise
URL: http://www.thatsjava.com/java-enterprise/59856/
the only thing you must do in your code to solve the problem is to add the following line:
props.put("mail.smtp.starttls.enable","true");
/*
* Created on 14/09/2005
*/
package br.com.bnb.mail;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* ...author gaucho
* TODO To change the template for this generated type comment go to Window -
*/
emailFromAddress);
java.security.Security
.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
session.setDebug(debug);
// create a message
msg.setFrom(addressFrom);
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
/**
*/
* Note the code is not mine, it is the result of many tryies and a copy of several fragments
found at google.. Thanks for all guys that drop these codes in the web. If you did the
original code, congratulations - I lost the link where I copied the original one and now I can
磘 give the credits to the original author , I just fixed some bugs and put it running up.
I tried the above code but unfortunately it still didn't work for me.
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at example.SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:77)
at example.SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:35)
Hello,
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1308)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1168)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:33
0)
at javax.mail.Service.connect(Service.java:258)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at br.com.bnb.mail.SendMailUsingAuthentication.postMail(SendMailUsingAut
hentication.java:88)
at br.com.bnb.mail.SendMailUsingAuthentication.main(SendMailUsingAuthent
ication.java:47)
/*
* Created on 14/09/2005
*/
package br.com.bnb.mail;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* ...author gaucho
* TODO To change the template for this generated type comment go to Window -
*/
emailFromAddress);
java.security.Security
.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
session.setDebug(debug);
// create a message
msg.setFrom(addressFrom);
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
/**
*/
Keep all your other code the same and add this where you are about to send your mail.
(i use the URLName construtor URLName(String, String, int, String, String, String).
trans.setStartTLS(true);
message.setSubject(subject);
message.setText(body);
trans.send(message);
trans.close();
This will work for you, it issues the SSL command first.
This is an application that sends a message but there is a problem the domain could not
be resolved
/*
* Notifier.java
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
/**
* ...author Trainee
*/
import java.util.*;
import java.sql.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
//SystemTray.getDefaultSystemTray().addTrayIcon(new TrayIcon(new
ImageIcon("imagefilename")));
t.start();
//email module
//emailThread.sendMessage();
simple.senderClassKo();*/
try
System.out.println("ethread");
catch(MessagingException me)
me.printStackTrace();
}*/
//dbc.DBConnect();
/*
//String to = "keikun_naruchan...yahoo.com";
String to = "jitendra...gmail.com";
props.put("mail.smtp.host", host);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
// Get session
// Define message
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
// Send message
//com.sun.mail.smtp.SMTPSSLTransport.send(message);
Transport.send(message);*/
}
}
class DBConnection
ResultSet rs = null;
try
Class.forName("org.postgresql.Driver");
statement = connection.createStatement();
/*
*/
rs = statement.executeQuery(sql);
while (rs.next())
//System.out.println("Record Found");
int notify1;
int notify2;
int notify3;
//Date expiredate;
int subtracted_date;
//firstname = (rs.getString(1));
subtracted_date = (rs.getInt(1));
ctrlno = (rs.getString(2));
notifyid = (rs.getString(3));
//email = (rs.getString(4));
email2[ctr] = (rs.getString(4));
notify1 = (rs.getInt(5));
notify2 = (rs.getInt(6));
notify3 = (rs.getInt(7));
//lastname = (rs.getString(2));
//out.println(contract.getCtrlno());
emailThread.sendMessage(DBConnection.email2, DBConnection.ctrlno);
//ctr++;
ctr++;
if (rs.next() == false)
ex.printStackTrace();
finally
try
if (rs != null)
{
rs.close();
if (statement != null)
statement.close();
if (connection != null)
connection.close();
ex.printStackTrace();
{
public void run()
while (true)
if(ampm == 0)
am_pm = "AM";
else
am_pm = "PM";
System.out.println("Time " + hour12 + ":" + min + ":" + sec + " " + am_pm);
if(sec == 10)
System.out.println("YIPEE");
//EmailThread emailThread = new EmailThread();
//emailThread.sendMessage(DBConnection.email2);
dbc.DBConnect();
try
Thread.sleep(1000);
catch(Exception e)
e.printStackTrace();
class SimpleSender
/**
*/
{
try
//String smtpServer="mail.kiksbalayon.com";
String smtpServer="localhost";
String to="johannazanza...yahoo.com";
String from="keikun_naruchan...yahoo.com";
String subject="hello";
System.exit(0);
}*/
/*public static void send(String smtpServer, String to, String from, String subject, String
body)
try
msg.setFrom(new InternetAddress(from));
// if (cc != null)
// msg.setRecipients(Message.RecipientType.CC
// ,InternetAddress.parse(cc, false));
msg.setSubject(subject);
msg.setText(body);
//msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
Transport.send(msg);
ex.printStackTrace();
}
}*/
//Authentication module
MyAuthenticator()
super();
// email module
try
{
String host = "localhost";
//String[] to = toEmail;
//"keikun_naruchan...yahoo.com";
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
// Get session
session.setDebug(debug);
// Define message
message.setFrom(new InternetAddress(from));
to = new InternetAddress(toEmail);
//System.out.println("EMAILTO:" + to);
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject("Contract Expiry");
message.setText(
);
// Send message
Transport.send(message);
catch(Exception me)
me.printStackTrace();
What does that mean? Are you getting an exception with a message
of that sort? If so, it probably means your basic networking configuration
has a problem and it can't find the name of the host you're trying to connect to.
that started this topic, this discussion should move to a new topic.
props.put("mail.smtp.starttls.enable","true");
If after this still doesn.t work., you should propably check if aren't running any processes in
your operating system, which scans outgoing mail (for example avast ). They can't support
TLS on port 25. So you have to turn this processes off.
Some servers can communicate via port 587, so if you add property
props.put("mail.smtp.port","587");
sometimes you get your mail application works fine together with scanners -)
2) You can use Telnet to determine what's wrong with sending mails and if connection is
encrypted..
Regards
Hi Seems I'm not the first to ask this question, but I didn't really find the answer to it, so
I'll post it again myself..When sending a mail using JavaMail SMTP I got some of the
header lines in the message body.How can this be avoided, or: what am I doing wrong ?Any
help would be highly ...
* SMTP without using Mail API
Dear all,I am attempting to write a simple mail program, without using the Java Mail
API.My code is as followsimport java.io.*;import java.net.*;import java.util.*;public class
Test{private String host_mailserver;private int port;private String recipient;private String
sender;private String ...
* SMTP Transport: SendFailedException
I have download de java mail example from sun, and I tryed to send a mail with a
picture. But I couldn't send the mail. I recived a mail that say that the smtp server did not
reach the recipient(s).One thing I want to ask is: Don't I need to put the password of the
smtp server? If yes, ...
* SMTP relay works with Thunderbird but not with Javamail
Hi all,I'm really clueless now and decided to ask for help here in this forum.I'm trying to
send a mail via an SMTP server which needs a login.I keep getting the error message
"javax.mail.SendFailedException: 554 <an_existing@mailaddress.de>: Relay access
denied"I read many postings in ...
Dear All,I'm badly hanging over here....with a stumbling block...in the progress......just, i
got blocked over here and dont know how to proceed further...the work i'm trying to do is:
have one client machine and a server machine... trying to upload a file from my client
machine to the server ...
* ZipFile closed: EJB Deployment Issue
Hi all,I am facing problems in the Ejb deployment. Please read the followingV r using
Weblogic 7.0 with jdk1.4Just take a luk at steps performed1. V compiled all the source
code, the ejbc compilation and the .ear generation thru ant(v 1.5) build scripts with
JDK1.4.12. When v tried deployin the ...
* ZipException
A new jaxb install and try to run the checkbook example from the docs. And I get:$ xjc
checkbook.dtd checkbook.xjsException in thread "main" java.util.zip.ZipException: The
system cannot find the path specifiedat java.util.zip.ZipFile.open(Native Method)at ...
* Zip help
How do we check if there are multiple files to unzip ?Is there a the method in the
java.util.zip that allow us to check for multiple files ? ...
* ZIP FILES
i'm interested in knowing how to zip and unzip files in java....can you help ...
* ZIP Compression
I've read some on this topic, but its still not clear to me.here's what I
got:try{FileOutputStream out = new FileOutputStream("zipFile.zip");zOut = new
ZipOutputStream(out);ZipEntry entry = new
ZipEntry("First");zOut.putNextEntry(entry);}catch(IOException e){}I build the Streams, but
where do ...
* your experiences with Websphere, Oracle OC4J and JRUN
I work for a county government and we are looking at J2EE servers. I want to do some
preliminary research and see what people seem to tthink about the three above
products.My background is Java training and no J2EE experience so I am going semi-blind
here except for the amount of reading I have ...
* Youden Graphs
Hello ,I require to create a youden Graph class. An applet would do good also as i have
to display this graph to my clients over the net .I was looking for a ready made class or a
pseudo code fr the same .Can any one help me ?Thank ...
* YACC vs Xalan
Hi, Is YACC an alternative to Xalan? If yes Could you please tell me which one is better
(easiest) to use with Xml and java.Thankssoumy ...
* Y is Stateless Session Bean is of type Session Bean?
Hi all!Statless Session Bean...It not maintaining a state ...then y its of type Session
Bean?...
*
Desktop Technologies
*
Enterprise Technologies
*
Java Core APIs
*
Java Core GUI APIs
*
Java Database Connectivity (JDBC)
*
Java Development Tools
*
Java Enterprise java bean & Java EE (EJB)
*
Java Essentials
*
Java HotSpot Virtual Machine
*
Java in Newer
*
Java Intermediate
*
Java Miscellaneous
*
Java Open Source Software
*
Java Products
*
Java Professional Certification
*
Java Programming
*
Java Server Pages (JSP)
*
Java Socket Programming
*
Sun ONE Studio
*
Swing / AWT / SWT / JFace
*
Web & Directory & Servers & Security
*
Web Tier APIs
Site Links: iTags .NET Framework Java Programming Database MSDN Software Network
Email spam Ms Excel Visual Basic Visual C&C++ Microsoft XP Win NT/2k3 eMsdn eDevs
Law Support by Law Knowledge
About|Tags Directory|privacy|feedback|Submit your Website|Spam Report
©2010 THATSJAVA.COM. All rights reserved. - 0.1 - Last Modified: Sat, 20 Nov 2010
18:37:17 GMT
web stats counter