本文整理汇总了Java中com.sun.mail.imap.IMAPSSLStore类的典型用法代码示例。如果您正苦于以下问题:Java IMAPSSLStore类的具体用法?Java IMAPSSLStore怎么用?Java IMAPSSLStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMAPSSLStore类属于com.sun.mail.imap包,在下文中一共展示了IMAPSSLStore类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: connectToImap
import com.sun.mail.imap.IMAPSSLStore; //导入依赖的package包/类
/**
* Connects and authenticates to an IMAP server with OAuth2. You must have
* called {@code initialize}.
*
* @param host Hostname of the imap server, for example {@code
* imap.googlemail.com}.
* @param port Port of the imap server, for example 993.
* @param userEmail Email address of the user to authenticate, for example
* {@code [email protected]}.
* @param oauthToken The user's OAuth token.
* @param debug Whether to enable debug logging on the IMAP connection.
*
* @return An authenticated IMAPStore that can be used for IMAP operations.
*/
public static IMAPStore connectToImap(String host, int port, String userEmail,
String oauthToken, boolean debug) throws Exception
{
Properties props = new Properties();
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
store.connect(host, port, userEmail, EMPTY_PASSWORD);
return store;
}
开发者ID:danielebufarini,项目名称:Reminders,代码行数:31,代码来源:OAuth2Authenticator.java
示例2: connectWithIMAPSSL
import com.sun.mail.imap.IMAPSSLStore; //导入依赖的package包/类
public Store connectWithIMAPSSL(BatchClassEmailConfiguration configuration) throws MessagingException {
Properties imapProps = new Properties();
imapProps.setProperty("mail.imap.socketFactory.class", MailConstants.SSL_FACTORY);
imapProps.setProperty("mail.imap.socketFactory.fallback", "false");
imapProps.setProperty("mail.imap.partialfetch", "false");
Integer portNumber = configuration.getPortNumber();
if (portNumber == null) {
LOGGER.error("Could not find port number. Trying with default value of 993");
portNumber = MailConstants.DEFAULT_PORT_NUMBER_IMAP;
}
URLName url = new URLName(configuration.getServerType(), configuration.getServerName(), portNumber, "", configuration
.getUserName(), configuration.getPassword());
session = Session.getInstance(imapProps, null);
store = new IMAPSSLStore(session, url);
store.connect();
return store;
}
开发者ID:kuzavas,项目名称:ephesoft,代码行数:23,代码来源:MailReceiverServiceImpl.java
示例3: connectToImap
import com.sun.mail.imap.IMAPSSLStore; //导入依赖的package包/类
/**
* Connects and authenticates to an IMAP server with OAuth2. You must have
* called {@code initialize}.
*
* @param host Hostname of the imap server, for example {@code
* imap.googlemail.com}.
* @param port Port of the imap server, for example 993.
* @param userEmail Email address of the user to authenticate, for example
* {@code [email protected]}.
* @param oauthToken The user's OAuth token.
* @param debug Whether to enable debug logging on the IMAP connection.
*
* @return An authenticated IMAPStore that can be used for IMAP operations.
*/
public static IMAPStore connectToImap(String host,
int port,
String userEmail,
String oauthToken,
boolean debug) throws Exception {
Properties props = new Properties();
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");
props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
final String emptyPassword = "";
store.connect(host, port, userEmail, emptyPassword);
return store;
}
开发者ID:google,项目名称:gmail-oauth2-tools,代码行数:33,代码来源:OAuth2Authenticator.java
示例4: connectToImap
import com.sun.mail.imap.IMAPSSLStore; //导入依赖的package包/类
/**
* Connects and authenticates to an IMAP server with XOAUTH. You must have
* called {@code initialize}.
*
* @param host Hostname of the imap server, for example {@code
* imap.googlemail.com}.
* @param port Port of the imap server, for example 993.
* @param userEmail Email address of the user to authenticate, for example
* {@code [email protected]}.
* @param oauthToken The user's OAuth token.
* @param oauthTokenSecret The user's OAuth token secret.
* @param consumer The application's OAuthConsumer. For testing, use
* {@code getAnonymousConsumer()}.
* @param debug Whether to enable debug logging on the IMAP connection.
*
* @return An authenticated IMAPSSLStore that can be used for IMAP operations.
*/
public static IMAPSSLStore connectToImap(String host,
int port,
String userEmail,
String oauthToken,
String oauthTokenSecret,
OAuthConsumer consumer,
boolean debug) throws Exception {
Properties props = new Properties();
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH");
props.put(XoauthSaslClientFactory.OAUTH_TOKEN_PROP,
oauthToken);
props.put(XoauthSaslClientFactory.OAUTH_TOKEN_SECRET_PROP,
oauthTokenSecret);
props.put(XoauthSaslClientFactory.CONSUMER_KEY_PROP,
consumer.consumerKey);
props.put(XoauthSaslClientFactory.CONSUMER_SECRET_PROP,
consumer.consumerSecret);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
final String emptyPassword = "";
store.connect(host, port, userEmail, emptyPassword);
return store;
}
开发者ID:google,项目名称:gmail-oauth2-tools,代码行数:45,代码来源:XoauthAuthenticator.java
示例5: main
import com.sun.mail.imap.IMAPSSLStore; //导入依赖的package包/类
/**
* Authenticates to IMAP with parameters passed in on the commandline.
*/
public static void main(String args[]) throws Exception {
if (args.length != 3) {
System.err.println(
"Usage: XoauthAuthenticator <email> <oauthToken> <oauthTokenSecret>");
return;
}
String email = args[0];
String oauthToken = args[1];
String oauthTokenSecret = args[2];
initialize();
IMAPSSLStore imapSslStore = connectToImap("imap.googlemail.com",
993,
email,
oauthToken,
oauthTokenSecret,
getAnonymousConsumer(),
true);
System.out.println("Successfully authenticated to IMAP.\n");
SMTPTransport smtpTransport = connectToSmtp("smtp.googlemail.com",
587,
email,
oauthToken,
oauthTokenSecret,
getAnonymousConsumer(),
true);
System.out.println("Successfully authenticated to SMTP.");
}
开发者ID:google,项目名称:gmail-oauth2-tools,代码行数:33,代码来源:XoauthAuthenticator.java
示例6: MailConnection
import com.sun.mail.imap.IMAPSSLStore; //导入依赖的package包/类
/**
* Construct a new Database MailConnection
* @param protocol the protocol used : MailConnection.PROTOCOL_POP3 or MailConnection.PROTOCOL_IMAP.
* @param server the target server (ip ou name)
* @param port port number on the server
* @param password
* @param usessl specify if the connection is established via SSL
* @param useproxy specify if we use proxy authentication
* @param proxyusername proxy authorised user
*/
public MailConnection(LogChannelInterface log, int protocol, String server, int port, String username,
String password, boolean usessl, boolean useproxy, String proxyusername) throws KettleException {
this.log=log;
//Get system properties
try {
this.prop = System.getProperties();
} catch (SecurityException s) {
this.prop = new Properties();
}
this.port=port;
this.server=server;
this.username=username;
this.password=password;
this.usessl=usessl;
this.protocol=protocol;
this.nrSavedMessages=0;
this.nrDeletedMessages=0;
this.nrMovedMessages=0;
this.nrSavedAttachedFiles=0;
this.messagenr=-1;
this.useproxy=useproxy;
this.proxyusername=proxyusername;
try{
if(useproxy) {
// Need here to pass a proxy
// use SASL authentication
this.prop.put("mail.imap.sasl.enable", "true");
this.prop.put("mail.imap.sasl.authorizationid", proxyusername);
}
if(protocol==MailConnectionMeta.PROTOCOL_POP3) {
this.prop.setProperty("mail.pop3s.rsetbeforequit","true");
this.prop.setProperty("mail.pop3.rsetbeforequit","true");
}
String protocolString=(protocol==MailConnectionMeta.PROTOCOL_POP3)?"pop3":"imap";
if(usessl) {
// Supports IMAP/POP3 connection with SSL, the connection is established via SSL.
this.prop.setProperty("mail."+protocolString+".socketFactory.class", "javax.net.ssl.SSLSocketFactory");
this.prop.setProperty("mail."+protocolString+".socketFactory.fallback", "false");
this.prop.setProperty("mail."+protocolString+".port",""+port);
this.prop.setProperty("mail."+protocolString+".socketFactory.port",""+port);
//Create session object
this.session = Session.getInstance(this.prop, null );
this.session.setDebug(log.isDebug());
if(this.port==-1) {
this.port=((protocol==MailConnectionMeta.PROTOCOL_POP3)?MailConnectionMeta.DEFAULT_SSL_POP3_PORT:MailConnectionMeta.DEFAULT_SSL_IMAP_PORT);
}
URLName url = new URLName(protocolString, server, port, "", username, password);
this.store = (protocol==MailConnectionMeta.PROTOCOL_POP3)?new POP3SSLStore(this.session, url):new IMAPSSLStore(this.session, url);
url=null;
} else {
this.session = Session.getInstance(this.prop, null);
this.session.setDebug(log.isDebug());
this.store = this.session.getStore(protocolString);
}
if(log.isDetailed()) log.logDetailed(BaseMessages.getString(PKG, "JobGetMailsFromPOP.NewConnectionDefined"));
}catch(Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "JobGetMailsFromPOP.Error.NewConnection",Const.NVL(this.server,"")),e);
}
}
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:79,代码来源:MailConnection.java
注:本文中的com.sun.mail.imap.IMAPSSLStore类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论