本文整理汇总了Java中javax.mail.URLName类的典型用法代码示例。如果您正苦于以下问题:Java URLName类的具体用法?Java URLName怎么用?Java URLName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
URLName类属于javax.mail包,在下文中一共展示了URLName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import javax.mail.URLName; //导入依赖的package包/类
@Override
public void connect() {
Properties properties = new Properties();
try {
int port = configuration.getPort();
String portS = String.valueOf(port);
properties.setProperty("mail.store.protocol", "pop3");
properties.setProperty("mail.pop3.port", portS);
properties.setProperty("mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.pop3.socketFactory.fallback", "true");
properties.setProperty("mail.pop3.port", portS);
properties.setProperty("mail.pop3.socketFactory.port", portS);
URLName url = new URLName("pop3s", configuration.getServer(), port, "",
configuration.getUsername(), configuration.getPassword());
Session session = Session.getInstance(properties, null);
store = session.getStore(url);
store.connect();
folder = store.getFolder(configuration.getFolderName());
folder.open(Folder.READ_WRITE);
} catch (MessagingException e) {
LOGGER.error("error - cannot connect to mail server", e);
throw new ConnectorException(e);
}
}
示例2: getConnection
import javax.mail.URLName; //导入依赖的package包/类
/**
* Get the connection to a mail store
*
* @param user whose mail store should be connected
* @param protocol protocol used to connect
* @return
* @throws MessagingException when unable to connect to the store
*/
private static Store getConnection(GreenMailUser user, String protocol) throws MessagingException {
Properties props = new Properties();
Session session = Session.getInstance(props);
int port;
if (PROTOCOL_POP3.equals(protocol)) {
port = 3110;
} else if (PROTOCOL_IMAP.equals(protocol)) {
port = 3143;
} else {
port = 3025;
props.put("mail.smtp.auth", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", "3025");
}
URLName urlName = new URLName(protocol, BIND_ADDRESS, port, null, user.getLogin(), user.getPassword());
Store store = session.getStore(urlName);
store.connect();
return store;
}
示例3: connectToImap
import javax.mail.URLName; //导入依赖的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;
}
示例4: connectToSmtp
import javax.mail.URLName; //导入依赖的package包/类
/**
* Connects and authenticates to an SMTP server with OAuth2. You must have
* called {@code initialize}.
*
* @param host Hostname of the smtp server, for example {@code
* smtp.googlemail.com}.
* @param port Port of the smtp server, for example 587.
* @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 connection.
*
* @return An authenticated SMTPTransport that can be used for SMTP
* operations.
*/
public static SMTPTransportInfo connectToSmtp(String host, int port, String userEmail,
String oauthToken, boolean debug) throws Exception
{
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "true");
props.put("mail.smtp.sasl.mechanisms", "XOAUTH2");
props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
// If the password is non-null, SMTP tries to do AUTH LOGIN.
transport.connect(host, port, userEmail, EMPTY_PASSWORD);
SMTPTransportInfo transportInfo = new SMTPTransportInfo();
transportInfo.session = session;
transportInfo.smtpTransport = transport;
return transportInfo;
}
示例5: connectWithPOP3SSL
import javax.mail.URLName; //导入依赖的package包/类
public Store connectWithPOP3SSL(BatchClassEmailConfiguration configuration) throws MessagingException {
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.socketFactory.class", MailConstants.SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
Integer portNumber = configuration.getPortNumber();
if (portNumber == null) {
LOGGER.error("Could not find port number. Trying with default value of 995");
portNumber = MailConstants.DEFAULT_PORT_NUMBER_POP3;
}
URLName url = new URLName(configuration.getServerType(), configuration.getServerName(), portNumber, "", configuration
.getUserName(), configuration.getPassword());
session = Session.getInstance(pop3Props, null);
store = new POP3SSLStore(session, url);
store.connect();
return store;
}
示例6: connectWithIMAPSSL
import javax.mail.URLName; //导入依赖的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;
}
示例7: connectWithPOP3SSL
import javax.mail.URLName; //导入依赖的package包/类
/**
* API to connect to the email configuration with POP3 server type.
*
* @param emailConfigData {@link EmailConfigurationData}
* @return
* @throws MessagingException {@link MessagingException}
* @throws AuthenticationFailedException {@link AuthenticationFailedException}
*/
public static Store connectWithPOP3SSL(final EmailConfigurationData emailConfigData) throws MessagingException,
AuthenticationFailedException {
LOGGER.info("Entering method connectWithPOP3SSL...");
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.socketFactory.class", IUtilCommonConstants.SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
Integer portNumber = emailConfigData.getPortNumber();
LOGGER.debug("Port Number :: " + portNumber);
if (portNumber == null) {
LOGGER.error("Could not find port number. Trying with default value of 995");
throw new MessagingException("Could not connect to port number " + portNumber
+ ". Try connecting with defualt port number " + IUtilCommonConstants.DEFAULT_PORT_NUMBER_POP3 + " for pop3 and "
+ IUtilCommonConstants.DEFAULT_PORT_NUMBER_IMAP + " for IMAP ");
}
URLName url = new URLName(emailConfigData.getServerType(), emailConfigData.getServerName(), portNumber, "", emailConfigData
.getUserName(), emailConfigData.getPassword());
Session session = Session.getInstance(pop3Props, null);
Store store = new POP3SSLStore(session, url);
store.connect();
LOGGER.info("Exiting method connectWithPOP3SSL...");
return store;
}
示例8: get
import javax.mail.URLName; //导入依赖的package包/类
public JavaxMailStorage get() throws MessagingException {
Properties properties = new Properties();
properties.setProperty("mail.store.protocol", "mstor");
properties.setProperty("mstor.mbox.metadataStrategy", "none");
properties.setProperty("mstor.mbox.cacheBuffers", "disabled");
properties.setProperty("mstor.mbox.bufferStrategy", "mapped");
properties.setProperty("mstor.metadata", "disabled");
properties.setProperty("mstor.mozillaCompatibility", "enabled");
Session session = Session.getDefaultInstance(properties);
// /Users/flan/Desktop/Copy of Marie's Mail/Mail/Mail/mail.lean.to
File mailbox = new File(commandLineArguments.mailboxFileName);
if (!mailbox.exists()) {
throw new MessagingException("No such mailbox:" + mailbox);
}
Store store = session.getStore(
new URLName("mstor:" + mailbox.getAbsolutePath()));
store.connect();
return new ThunderbirdMailStorage(
logger,
new JavaxMailFolder(store.getDefaultFolder()),
statusParser);
}
示例9: connectToImap
import javax.mail.URLName; //导入依赖的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;
}
示例10: connectToSmtp
import javax.mail.URLName; //导入依赖的package包/类
/**
* Connects and authenticates to an SMTP server with OAuth2. You must have
* called {@code initialize}.
*
* @param host Hostname of the smtp server, for example {@code
* smtp.googlemail.com}.
* @param port Port of the smtp server, for example 587.
* @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 connection.
*
* @return An authenticated SMTPTransport that can be used for SMTP
* operations.
*/
public static SMTPTransport connectToSmtp(String host,
int port,
String userEmail,
String oauthToken,
boolean debug) throws Exception {
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "true");
props.put("mail.smtp.sasl.mechanisms", "XOAUTH2");
props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
// If the password is non-null, SMTP tries to do AUTH LOGIN.
final String emptyPassword = "";
transport.connect(host, port, userEmail, emptyPassword);
return transport;
}
示例11: setUp
import javax.mail.URLName; //导入依赖的package包/类
@Before
public void setUp() throws MessagingException, IOException {
Properties properties = new Properties();
properties.put("mail.files.path", "target" + File.separatorChar + "output");
Session session = Session.getDefaultInstance(properties);
transport = new AbstractFileTransport(session, new URLName("AbstractFileDev")) {
@Override
protected void writeMessage(Message message, OutputStream os) throws IOException, MessagingException {
// do nothing
}
@Override
protected String getFilenameExtension() {
return BASE_EXT;
}
};
cleanup();
}
示例12: setUp
import javax.mail.URLName; //导入依赖的package包/类
@Before
public void setUp() throws MessagingException, IOException {
Properties properties = new Properties();
properties.put("mail.files.path", "target" + File.separatorChar + "output");
Session session = Session.getDefaultInstance(properties);
message = new MimeMessage(session);
message.setFrom("Test <[email protected]>");
connectionListener = Mockito.mock(ConnectionListener.class);
transportListener = Mockito.mock(TransportListener.class);
transport = new AbstractTransport(session, new URLName("AbstractDev")) {
@Override
public void sendMessage(Message message, Address[] addresses) throws MessagingException {
validateAndPrepare(message, addresses);
}
};
transport.addConnectionListener(connectionListener);
transport.addTransportListener(transportListener);
}
示例13: setUp
import javax.mail.URLName; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestContextFactory.class.getName());
QueueConnectionFactory queueConnectionFactory = Mockito.mock(QueueConnectionFactory.class);
Queue queue = Mockito.mock(Queue.class);
Context context = Mockito.mock(Context.class);
TestContextFactory.context = context;
when(context.lookup(eq("jms/queueConnectionFactory"))).thenReturn(queueConnectionFactory);
when(context.lookup(eq("jms/mailQueue"))).thenReturn(queue);
queueSender = Mockito.mock(QueueSender.class);
QueueConnection queueConnection = Mockito.mock(QueueConnection.class);
when(queueConnectionFactory.createQueueConnection()).thenReturn(queueConnection);
when(queueConnectionFactory.createQueueConnection(anyString(), anyString())).thenReturn(queueConnection);
QueueSession queueSession = Mockito.mock(QueueSession.class);
bytesMessage = Mockito.mock(BytesMessage.class);
when(queueSession.createBytesMessage()).thenReturn(bytesMessage);
when(queueConnection.createQueueSession(anyBoolean(), anyInt())).thenReturn(queueSession);
when(queueSession.createSender(eq(queue))).thenReturn(queueSender);
transport = new SmtpJmsTransport(Session.getDefaultInstance(new Properties()), new URLName("jms"));
transportListener = Mockito.mock(TransportListener.class);
transport.addTransportListener(transportListener);
}
示例14: testDoNotCheckFormHeader
import javax.mail.URLName; //导入依赖的package包/类
@Test
public void testDoNotCheckFormHeader() throws Exception {
Properties properties = new Properties();
properties.setProperty("mail.smtpjms.validateFrom", "false");
SmtpJmsTransport transport = new SmtpJmsTransport(Session.getInstance(properties), new URLName("jms"));
Message message = Mockito.mock(Message.class);
TransportListener listener = Mockito.mock(TransportListener.class);
Address[] to = new Address[]{ new InternetAddress("[email protected]") };
transport.addTransportListener(listener);
transport.sendMessage(message, to);
waitForListeners();
ArgumentCaptor<TransportEvent> transportEventArgumentCaptor = ArgumentCaptor.forClass(TransportEvent.class);
verify(listener).messageDelivered(transportEventArgumentCaptor.capture());
TransportEvent event = transportEventArgumentCaptor.getValue();
assertEquals(message, event.getMessage());
assertEquals(TransportEvent.MESSAGE_DELIVERED, event.getType());
assertArrayEquals(to, event.getValidSentAddresses());
}
示例15: connectToSmtp
import javax.mail.URLName; //导入依赖的package包/类
private SMTPTransport connectToSmtp(String host, int port, String userEmail,
String oauthToken, boolean debug) throws MessagingException {
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "false");
props.put("mail.smtp.ssl.enable", true);
session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
// If the password is non-null, SMTP tries to do AUTH LOGIN.
final String emptyPassword = null;
transport.connect(host, port, userEmail, emptyPassword);
byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", userEmail,
oauthToken).getBytes();
response = BASE64EncoderStream.encode(response);
transport.issueCommand("AUTH XOAUTH2 " + new String(response),
235);
return transport;
}