本文整理汇总了Java中javax.mail.NoSuchProviderException类的典型用法代码示例。如果您正苦于以下问题:Java NoSuchProviderException类的具体用法?Java NoSuchProviderException怎么用?Java NoSuchProviderException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NoSuchProviderException类属于javax.mail包,在下文中一共展示了NoSuchProviderException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public void sendMessage (Message oMsg,
Address[] aAdrFrom, Address[] aAdrReply,
Address[] aAdrTo, Address[] aAdrCc, Address[] aAdrBcc)
throws NoSuchProviderException,SendFailedException,ParseException,
MessagingException,NullPointerException {
oMsg.addFrom(aAdrFrom);
if (null==aAdrReply)
oMsg.setReplyTo(aAdrReply);
else
oMsg.setReplyTo(aAdrFrom);
if (aAdrTo!=null) oMsg.addRecipients(javax.mail.Message.RecipientType.TO, aAdrTo);
if (aAdrCc!=null) oMsg.addRecipients(javax.mail.Message.RecipientType.CC, aAdrCc);
if (aAdrBcc!=null) oMsg.addRecipients(javax.mail.Message.RecipientType.BCC, aAdrBcc);
oMsg.setSentDate(new java.util.Date());
Transport.send(oMsg);
}
示例2: markMessagesAsRead
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public void markMessagesAsRead(String[] ids, boolean seen) throws NoSuchProviderException, MessagingException, IOException {
IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
folder.open(Folder.READ_WRITE);
UIDFolder uidFolder = folder;
Message[] msgs;
long[] uids = new long[ids.length];
int i = 0;
for (String s : ids) {
try {
uids[i++] = Long.parseLong(s);
} catch (Exception ex) {
Log.d("rgai", "", ex);
}
}
// TODO: if instance not support UID, then use simple id
msgs = uidFolder.getMessagesByUID(uids);
folder.setFlags(msgs, new Flags(Flags.Flag.SEEN), seen);
folder.close(false);
}
示例3: run
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
@Override
public void run() {
//we only need to send the message so we use smtps
try (Transport transport = session.getTransport()) {
EmailConfiguration emailConfig = plugin.getConfigManager().getGeneral().getEmail();
//connect to host and send message
if (!transport.isConnected()) {
String password = emailConfig.getPassword();
transport.connect(emailConfig.getHost(), emailConfig.getAccount(), password);
}
transport.sendMessage(email, email.getAllRecipients());
player.sendMessage(plugin.getConfigManager().getText().getMailSent());
} catch (NoSuchProviderException providerEx) {
plugin.getLogger().error("Transport provider not found", providerEx);
plugin.getLogger().error("Registered providers: {}", Arrays.asList(session.getProviders()));
player.sendMessage(plugin.getConfigManager().getText().getErrorCommand());
} catch (MessagingException messagingEx) {
plugin.getLogger().error("Error sending email", messagingEx);
player.sendMessage(plugin.getConfigManager().getText().getErrorCommand());
}
}
示例4: init
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
@PostConstruct
public void init() {
if (session == null) {
throw new IllegalStateException("JavaMail session is null.");
}
javaMailSessionDelegate = new JavaMailSessionDelegate() {
@Override
public Transport findTransport(String protocolToUse) throws NoSuchProviderException {
return session.getTransport(protocolToUse);
}
@Override
public MimeMessage createMimeMessage(InputStream inputStream) throws MessagingException {
return new MimeMessage(session, inputStream);
}
};
}
示例5: EmailDownloaderDialog
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public EmailDownloaderDialog(java.awt.Frame parent, boolean modal,
final Case aCase, final EmailConfiguration emailConfiguration) throws SQLException, NoSuchProviderException, MessagingException, IOException, Exception {
super(parent, modal);
initComponents();
setLocationRelativeTo(parent);
this.DownloadProgressBar.setIndeterminate(true);
this.aCase = aCase;
this.emailConfiguration = emailConfiguration;
this.onlineEmailDownloader = new OnlineEmailDownloader(this,
this.aCase.getCaseLocation() + "\\" + ApplicationConstants.CASE_ONLINE_EMAIL_ATTACHMENTS_FOLDER,
this.aCase.getCaseLocation() + "\\" + ApplicationConstants.CASE_EMAIL_DB_FOLDER,
this.aCase.getCaseLocation() + "\\" + ApplicationConstants.CASE_ARCHIVE_FOLDER
);
}
示例6: testJavaMailProperties
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public void testJavaMailProperties() throws MessagingException {
Properties props = new Properties();
props.setProperty("bogusKey", "bogusValue");
MockJavaMailSender sender = new MockJavaMailSender() {
@Override
protected Transport getTransport(Session sess) throws NoSuchProviderException {
assertEquals("bogusValue", sess.getProperty("bogusKey"));
return super.getTransport(sess);
}
};
sender.setJavaMailProperties(props);
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessage mimeMessage = sender.createMimeMessage();
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
sender.send(mimeMessage);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(mimeMessage, sender.transport.getSentMessage(0));
}
示例7: retrieveMail
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
private void retrieveMail() throws NoSuchProviderException,
MessagingException, IOException {
Properties properties = new Properties();
Session session = Session.getInstance(properties);
Store store =
session.getStore(new URLName("pop3://john:[email protected]:"
+ PORT_POP + "/INBOX"));
store.connect();
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
assertEquals(1, messages.length);
Message message = messages[0];
assertEquals("Hello World!\r\n", message.getContent());
message.setFlag(Flags.Flag.DELETED, true);
folder.close(true);
store.close();
}
示例8: getStore
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
/**
* Connects to imap, returns a store.
*
* @return the store where, where you can read the emails
* @throws NoSuchProviderException
* @throws MessagingException
* @throws AuthenticationFailedException
*/
private synchronized Store getStore() throws NoSuchProviderException, MessagingException, AuthenticationFailedException {
Properties props = System.getProperties();
this.setProperties(props);
Session session = Session.getDefaultInstance(props, null);
Store store;
if (this.account.isSsl()) {
store = session.getStore("imaps");
} else {
store = session.getStore("imap");
}
Log.d("rgai3", "connecting with account: " + account);
store.connect(account.getImapAddress(), account.getEmail(), account.getPassword());
return store;
}
示例9: markMessageAsRead
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
@Override
public void markMessageAsRead(String id, boolean seen) throws NoSuchProviderException, MessagingException, IOException {
IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
folder.open(Folder.READ_WRITE);
UIDFolder uidFolder = (UIDFolder)folder;
Message ms = uidFolder.getMessageByUID(Long.parseLong(id));
if (ms != null) {
ms.setFlag(Flags.Flag.SEEN, seen);
}
folder.close(false);
}
示例10: deleteMessage
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public void deleteMessage(String id) throws NoSuchProviderException, MessagingException, IOException {
IMAPFolder folder = (IMAPFolder)getStore().getFolder("Inbox");
folder.open(Folder.READ_WRITE);
UIDFolder uidFolder = (UIDFolder)folder;
Message ms = uidFolder.getMessageByUID(Long.parseLong(id));
if (ms != null) {
ms.setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
示例11: sendMessage
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
private void sendMessage() throws NoSuchProviderException, MessagingException, IOException {
props = PropertiesReader.getProps();
props.list(System.out);
System.out.println("\n========message follows==========\n");
session = Session.getInstance(props);
session.setDebug(true);
message = new MimeMessage(session);
String host = props.getProperty("mail.smtp.host");
String user = props.getProperty("mail.smtp.user");
String password = props.getProperty("mail.smtp.password");
int port = Integer.parseInt(props.getProperty("mail.smtp.port"));
System.out.println(host + user + password + port);
message.setFrom(new InternetAddress(props.getProperty("mail.smtp.user")));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(props.getProperty("mail.smtp.user"), false));
message.setText("hello gmail");
System.out.println(message.getFrom().toString());
System.out.println(message.getRecipients(Message.RecipientType.TO).toString());
System.out.println(message.getContent().toString());
transport = (SMTPTransport) session.getTransport("smtp");
System.out.println("trying...");
transport.connect(host, port, user, password);
System.out.println("...connected");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
示例12: sendMessage
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
private void sendMessage() throws NoSuchProviderException, MessagingException, IOException {
final Properties props = PropertiesReader.getProps();
props.list(System.out);
System.out.println("\n========message follows==========\n");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(props.getProperty("mail.smtp.username"), props.getProperty("mail.smtp.password"));
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(props.getProperty("mail.smtp.username")));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(props.getProperty("mail.smtp.username")));
message.setSubject("Testing Subject");
message.setText("Dear Google,\n\n please accept this authenticator.");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
示例13: main
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, NoSuchProviderException, MessagingException {
Properties properties = new Properties();
properties.load(new InputStreamReader(
ClassLoader.class.getResourceAsStream("/account.properties"), "UTF-8"));
final String HOST = properties.getProperty("HOST");
final String PORT = properties.getProperty("PORT");
final String USER = properties.getProperty("USER");
final String PASSWORD = properties.getProperty("PASSWORD");
System.out.println(properties);
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties gmailProperties = new Properties();
gmailProperties.put("mail.imap.starttls.enable","true");
gmailProperties.put("mail.imap.auth", "true");
gmailProperties.put("mail.imap.socketFactory.port", PORT);
gmailProperties.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
gmailProperties.put("mail.imap.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(gmailProperties, null);
Store store = session.getStore("imap");
store.connect(HOST, USER, PASSWORD);
Folder folder = store.getFolder(properties.getProperty("LABEL"));
folder.open(Folder.READ_ONLY);
for (Message message : folder.getMessages()) {
System.out.printf("Subject: %s\n", message.getSubject());
System.out.printf("Received Date: %s\n", message.getReceivedDate());
System.out.printf("Content:\n%s\n", getText(message.getContent()));
}
folder.close(false);
}
示例14: senderConnect
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public void senderConnect() throws NoSuchProviderException, MessagingException {
senderSession = Session.getInstance(pManager.getSenderProps());
//senderSession.setDebugOut(pManager.get_Log_Stream());
transport = (SMTPTransport)(senderSession.getTransport("smtp"));
transport.connect(pManager.get_SENDER_User(), pManager.get_SENDER_Pass());
}
示例15: receiverConnect
import javax.mail.NoSuchProviderException; //导入依赖的package包/类
public void receiverConnect() throws NoSuchProviderException, MessagingException {
receiverSession = Session.getInstance(pManager.getReceiverProps());
//receiverSession.setDebugOut(pManager.get_Log_Stream());
store = receiverSession.getStore(pManager.get_RECEIVER_Protocol());
store.connect(pManager.get_RECEIVER_User(), pManager.get_RECEIVER_Pass());
}