Two sample code using javamail
2004-08-25 11:38
483 查看
package vincent.mail;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.mail.*;
/**
* @author vincent.yang
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class retrieveEmail {
public static void main(String args[]) throws Exception{
String host = "xxxxx";
String username = "xxxxxx";
String password = "xxxxxxx";
Properties prop = new Properties();
Session session = Session.getDefaultInstance(prop,null);
Store store = session.getStore("pop3");
store.connect(host,username,password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
Message msg[] = folder.getMessages();
for(int i=0,n=msg.length;i<n;i++){
System.out.println(i + ": " + msg[i].getFrom()[0] + msg[i].getSubject());
System.out.println("Do you wanna read the message? [y/n]");
String line = bReader.readLine();
if("y".equals(line)){
System.out.println(msg[i].getContent());
}
else if("n".equals(line)){
break;
}
folder.close(false);
store.close();
}
}
}
*****************************************************************************
package vincent.mail;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
/**
* @author vincent.yang
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class sendMail {
public static void main(String args[]) throws Exception{
//the host for smtp
String host = "xxxx";//xxxx
String from = "xxxxx";
String to = "xxxx";
Properties prop = System.getProperties();
prop.put("mail.stmp.host",host);
//prop.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(prop,null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
msg.setSubject("cool man");
msg.setText("Hello,I am cool man");
Transport transport = session.getTransport("smtp");
transport.connect(host,"vincentyang","56944185");
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.mail.*;
/**
* @author vincent.yang
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class retrieveEmail {
public static void main(String args[]) throws Exception{
String host = "xxxxx";
String username = "xxxxxx";
String password = "xxxxxxx";
Properties prop = new Properties();
Session session = Session.getDefaultInstance(prop,null);
Store store = session.getStore("pop3");
store.connect(host,username,password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
Message msg[] = folder.getMessages();
for(int i=0,n=msg.length;i<n;i++){
System.out.println(i + ": " + msg[i].getFrom()[0] + msg[i].getSubject());
System.out.println("Do you wanna read the message? [y/n]");
String line = bReader.readLine();
if("y".equals(line)){
System.out.println(msg[i].getContent());
}
else if("n".equals(line)){
break;
}
folder.close(false);
store.close();
}
}
}
*****************************************************************************
package vincent.mail;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
/**
* @author vincent.yang
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class sendMail {
public static void main(String args[]) throws Exception{
//the host for smtp
String host = "xxxx";//xxxx
String from = "xxxxx";
String to = "xxxx";
Properties prop = System.getProperties();
prop.put("mail.stmp.host",host);
//prop.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(prop,null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
msg.setSubject("cool man");
msg.setText("Hello,I am cool man");
Transport transport = session.getTransport("smtp");
transport.connect(host,"vincentyang","56944185");
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
}
}
相关文章推荐
- WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- connect to Gmail Imap using javamail
- Using Custom Java code in ODI
- Leet Code 29 Divide Two Integers - 两个整数相除 - Java
- Access GMail with imap using java mail api
- Mysql : C# sample code using ObjectDataSources
- leecode algo2: Add Two Numbers (Java)
- Using Bytecode Outline to View Java bytecode in Eclipse
- Java ThreadLocal - How to use and code sample
- [我研究] Detecting Malicious Java Code Using Virtual Machine Auditing - 2
- [hadoop] WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- LeetCode_2_AddTwoNumbers(Java Code)
- HADOOP:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- Trace every instruction in java bytecode using BCEL
- 2.【排序】Merge Two Sorted Lists--Accepted Java code
- Java Thread Local – How to use and code sample
- 17/11/24 05:08:44 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- HADOOP:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable终于解决了
- leecode algo1: Two Sum (Java)
- Manage, Administrate and Monitor GlassFish v3 from Java code usingAMX & JMX