| | |
mialing code execution is stoped at transport.send(msg)
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.activation.*;
import java.io.*;
public class SimpleSender
{
public static void main(String args[])
{
try
{
String smtpServer=args[0];
String to=args[1];
String from=args[2];
String body=args[3];
send(smtpServer, to, from,body);
}
catch (Exception ex)
{
System.out.println("Usage :\njava SimpleSender server to from body");
}
System.exit(0);
}
public static void send(String smtpServer, String to, String from, String body)
{
try
{
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
msg.setSubject("Test Mail thru java");
msg.setContent(body,"text/plain");
msg.setSentDate(new Date());
System.out.println("Message sent OK1.");
Transport.send(msg);
System.out.println("Message sent OK2.");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
import javax.mail.internet.*;
import java.util.*;
import javax.activation.*;
import java.io.*;
public class SimpleSender
{
public static void main(String args[])
{
try
{
String smtpServer=args[0];
String to=args[1];
String from=args[2];
String body=args[3];
send(smtpServer, to, from,body);
}
catch (Exception ex)
{
System.out.println("Usage :\njava SimpleSender server to from body");
}
System.exit(0);
}
public static void send(String smtpServer, String to, String from, String body)
{
try
{
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
msg.setSubject("Test Mail thru java");
msg.setContent(body,"text/plain");
msg.setSentDate(new Date());
System.out.println("Message sent OK1.");
Transport.send(msg);
System.out.println("Message sent OK2.");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
![]() |
Other Threads in the Java Forum
- Previous Thread: is it possible to run the java application in a mysql linux server
- Next Thread: how to cal crystal report from swings
Views: 727 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation binary bluetooth businessintelligence card chat class classes client code collision component crashcourse database detection draw eclipse error event exception file fractal free game gis givemetehcodez graphics gui helpwithhomework html ide image input integer integration j2me java javadoc javafx javaprojects jmf jni jpanel julia jvm linux list loop machine map method methods migrate mobile netbeans newbie nls number object oracle os physics print problem program programming project radio recursion remote scanner screen security server set size sms socket sort sql string swing test textfield threads time transfer tree trolltech utility windows






