Java 类javax.mail.NoSuchProviderException 实例源码
项目:zesped
文件:MailSessionHandler.java
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);
}
项目:yako
文件:SimpleEmailMessageProvider.java
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);
}
项目:FlexibleLogin
文件:SendMailTask.java
@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());
}
}
项目:javamail
文件:JMS2JavaMail.java
@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);
}
};
}
项目:DEM
文件:EmailDownloaderDialog.java
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
);
}
项目:yako
文件:SimpleEmailMessageProvider.java
/**
* 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;
}
项目:yako
文件:SimpleEmailMessageProvider.java
@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);
}
项目:yako
文件:SimpleEmailMessageProvider.java
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);
}
项目:MailFromNNTP
文件:Gmail.java
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();
}
项目:MailFromNNTP
文件:SendTLS.java
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);
}
}
项目:MiscellaneousStudy
文件:GetMail.java
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);
}
项目:MailCopier
文件:MailCopier.java
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());
}
项目:MailCopier
文件:MailCopier.java
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());
}
项目:alfresco-repository
文件:AlfrescoJavaMailSender.java
/**
* @return A new {@code PooledTransportWrapper} which borrows a pooled {@link Transport} on connect, and returns it to
* the pool on close.
*/
@Override
protected Transport getTransport(Session session) throws NoSuchProviderException
{
return new PooledTransportWrapper(transportPool, session, getProtocol());
}
项目:ats-framework
文件:MailSender.java
/**
* Initialize the SMTP session
*
* @throws ActionException
*/
private void initSession() throws ActionException {
// initialize the mail session with the current properties
session = Session.getInstance(mailProperties);
// user can get more debug info with the session's debug mode
session.setDebug(configurator.getMailSessionDebugMode());
// initialize the SMPT transport
try {
transport = session.getTransport("smtp");
} catch (NoSuchProviderException e) {
throw new ActionException(e);
}
}
项目:lams
文件:JavaMailSenderImpl.java
/**
* Obtain a Transport object from the given JavaMail Session,
* using the configured protocol.
* <p>Can be overridden in subclasses, e.g. to return a mock Transport object.
* @see javax.mail.Session#getTransport(String)
* @see #getProtocol()
*/
protected Transport getTransport(Session session) throws NoSuchProviderException {
String protocol = getProtocol();
if (protocol == null) {
protocol = session.getProperty("mail.transport.protocol");
if (protocol == null) {
protocol = DEFAULT_PROTOCOL;
}
}
return session.getTransport(protocol);
}
项目:Java-9-Programming-Blueprints
文件:AccountProcessor.java
private void getImapSession() throws MessagingException, NoSuchProviderException {
Properties props = new Properties();
props.put("mail.imap.ssl.trust", "*");
props.put("mail.imaps.ssl.trust", "*");
props.setProperty("mail.imap.starttls.enable", Boolean.toString(account.isUseSsl()));
Session session = Session.getInstance(props, null);
store = session.getStore(account.isUseSsl() ? "imaps" : "imap");
store.connect(account.getServerName(), account.getUserName(), account.getPassword());
}
项目:libraries
文件:MailSenderFactory.java
public IMailSender create(final String server, final String userName, final IPassword password)
throws CreationException {
try {
return new MailSender(
this.session.getTransport("smtps"), //$NON-NLS-1$
this.passwordCoder,
new MimeMessageFactory(this.session),
server,
userName,
password);
} catch (final NoSuchProviderException exception) {
throw new CreationException(exception.getMessage(), exception);
}
}
项目:spring4-understanding
文件:JavaMailSenderImpl.java
/**
* Obtain a Transport object from the given JavaMail Session,
* using the configured protocol.
* <p>Can be overridden in subclasses, e.g. to return a mock Transport object.
* @see javax.mail.Session#getTransport(String)
* @see #getSession()
* @see #getProtocol()
*/
protected Transport getTransport(Session session) throws NoSuchProviderException {
String protocol = getProtocol();
if (protocol == null) {
protocol = session.getProperty("mail.transport.protocol");
if (protocol == null) {
protocol = DEFAULT_PROTOCOL;
}
}
return session.getTransport(protocol);
}
项目:hermes
文件:SmtpMail.java
/**
* Get and SMTP transport object for the session ses
*
* @param ses
* @return
* @throws SmtpMailException
* @throws NoSuchProviderException
*/
private Transport getTransport(Session ses, String prot)
throws SmtpMailException {
try {
return ses.getTransport(prot);
} catch (NoSuchProviderException e) {
throw new SmtpMailException("No such provider for this protocol.",
e);
}
}
项目:smtp-connection-pool
文件:TransportStrategyFactory.java
public static TransportStrategy newSessiontStrategy() {
return new TransportStrategy() {
@Override
public Transport getTransport(Session session) throws NoSuchProviderException {
return session.getTransport();
}
};
}
项目:smtp-connection-pool
文件:TransportStrategyFactory.java
public static TransportStrategy newProtocolStrategy(final String protocol) {
return new TransportStrategy() {
@Override
public Transport getTransport(Session session) throws NoSuchProviderException {
return session.getTransport(protocol);
}
};
}
项目:smtp-connection-pool
文件:TransportStrategyFactory.java
public static TransportStrategy newUrlNameStrategy(final URLName urlName) {
return new TransportStrategy() {
@Override
public Transport getTransport(Session session) throws NoSuchProviderException {
return session.getTransport(urlName);
}
};
}
项目:smtp-connection-pool
文件:TransportStrategyFactory.java
public static TransportStrategy newAddressStrategy(final Address address) {
return new TransportStrategy() {
@Override
public Transport getTransport(Session session) throws NoSuchProviderException {
return session.getTransport(address);
}
};
}
项目:smtp-connection-pool
文件:TransportStrategyFactory.java
public static TransportStrategy newProviderStrategy(final Provider provider) {
return new TransportStrategy() {
@Override
public Transport getTransport(Session session) throws NoSuchProviderException {
return session.getTransport(provider);
}
};
}
项目:packagedrone
文件:DefaultMailService.java
private void sendMessage ( final Message message ) throws MessagingException, NoSuchProviderException
{
final ClassLoader oldClassLoader = Thread.currentThread ().getContextClassLoader ();
Thread.currentThread ().setContextClassLoader ( getClass ().getClassLoader () );
try
{
// commit
message.saveChanges ();
// connect
final Transport transport = this.session.getTransport ();
transport.connect ();
// send
try
{
transport.sendMessage ( message, message.getAllRecipients () );
}
finally
{
// close
transport.close ();
}
}
finally
{
Thread.currentThread ().setContextClassLoader ( oldClassLoader );
}
}
项目:baleen
文件:EmailReader.java
@Override
protected void doInitialize(UimaContext context) throws ResourceInitializationException {
validateParams();
try{
extractor = getContentExtractor(contentExtractor);
}catch(InvalidParameterException ipe){
throw new ResourceInitializationException(ipe);
}
extractor.initialize(context, getConfigParameters(context));
authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user, pass);
}
};
Properties prop = new Properties();
prop.put("mail.store.protocol", protocol);
prop.put("mail.host", server);
prop.put("mail."+protocol+".port", port);
prop.put("mail.user", user);
session = Session.getInstance(prop, authenticator);
try {
store = session.getStore();
} catch (NoSuchProviderException e) {
throw new ResourceInitializationException(e);
}
try{
store.connect();
inboxFolder = store.getFolder(inbox);
reopenConnection();
}catch(MessagingException me){
throw new ResourceInitializationException(me);
}
}
项目:Lucee4
文件:SMTPClient.java
public static SessionAndTransport getSessionAndTransport(lucee.runtime.config.Config config,String hostName, int port,
String username, String password, long lifeTimesan, long idleTimespan,int socketTimeout,
boolean tls,boolean ssl,boolean sendPartial, boolean newConnection) throws NoSuchProviderException, MessagingException {
Properties props = createProperties(config,hostName,port,username,password,tls,ssl,sendPartial,socketTimeout);
Authenticator auth=null;
if(!StringUtil.isEmpty(username))
auth=new SMTPAuthenticator( username, password );
return newConnection?new SessionAndTransport(hash(props), props, auth,lifeTimesan,idleTimespan):
SMTPConnectionPool.getSessionAndTransport(props,hash(props),auth,lifeTimesan,idleTimespan);
}
项目:Lucee4
文件:SMTPConnectionPool.java
SessionAndTransport(String key, Properties props,Authenticator auth, long lifeTimespan, long idleTimespan) throws NoSuchProviderException {
this.key=key;
this.session=createSession(key, props, auth);
this.transport=session.getTransport("smtp");
this.created=System.currentTimeMillis();
this.lifeTimespan=lifeTimespan;
this.idleTimespan=idleTimespan;
touch();
}
项目:JForum
文件:Spammer.java
private void dispatchAuthenticatedMessage() throws NoSuchProviderException {
if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
int batchSize = this.config.getInt(ConfigKeys.MAIL_BATCH_SIZE);
int total = (int)Math.ceil((double)this.users.size() / (double)batchSize);
Iterator<User> iterator = this.users.iterator();
for (int i = 0; i < total; i++) {
this.dispatchNoMoreThanBatchSize(iterator, batchSize);
}
}
}
项目:Lucee
文件:SMTPConnectionPool.java
SessionAndTransport(String key, Properties props,Authenticator auth, long lifeTimespan, long idleTimespan) throws NoSuchProviderException {
this.key=key;
this.session=createSession(key, props, auth);
this.transport=session.getTransport("smtp");
this.created=System.currentTimeMillis();
this.lifeTimespan=lifeTimespan;
this.idleTimespan=idleTimespan;
touch();
}
项目:FlexibleLogin
文件:ForgotPasswordCommand.java
private Session buildSession(EmailConfiguration emailConfig) {
Properties properties = new Properties();
properties.setProperty("mail.smtp.host", emailConfig.getHost());
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.port", String.valueOf(emailConfig.getPort()));
//ssl
properties.setProperty("mail.smtp.socketFactory.port", String.valueOf(emailConfig.getPort()));
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
properties.setProperty("mail.smtp.starttls.enable", String.valueOf(true));
properties.setProperty("mail.smtp.ssl.checkserveridentity", "true");
properties.setProperty("mail.transport.protocol", "flexiblelogin");
Session session = Session.getDefaultInstance(properties);
//explicit override stmp provider because of issues with relocation
try {
session.setProvider(new Provider(Type.TRANSPORT, "smtps",
"flexiblelogin.sun.mail.smtp.SMTPSSLTransport", "Oracle", "1.6.0"));
session.setProvider(new Provider(Type.TRANSPORT, "flexiblelogin",
"flexiblelogin.sun.mail.smtp.SMTPSSLTransport", "Oracle", "1.6.0"));
} catch (NoSuchProviderException noSuchProvider) {
logger.error("Failed to add STMP provider", noSuchProvider);
}
return session;
}
项目:community-edition-old
文件:AlfrescoJavaMailSender.java
/**
* @return A new {@code PooledTransportWrapper} which borrows a pooled {@link Transport} on connect, and returns it to
* the pool on close.
*/
@Override
protected Transport getTransport(Session session) throws NoSuchProviderException
{
return new PooledTransportWrapper(transportPool, session, getProtocol());
}
项目:DEM
文件:OnlineEmailDownloader.java
/**
* static factory that read all message from user account and store it in list
* @param username the name of the account
* @param password the password of the account
* @return EmailReader object that contain all the messages in list
*/
public static OnlineEmailDownloader newInstance(EmailDownloaderDialog dialogue,
String attachmentsPath, String dbPath, String strTmpPath) throws SQLException, NoSuchProviderException, MessagingException, IOException {
// check null values
checkNull("attachmentsPath must be not null", attachmentsPath);
checkNull("dbPath must be not null", dbPath);
checkNotEmptyString("attachmentsPath must be not empty string", attachmentsPath);
checkNotEmptyString("dbPath must be not empty string", dbPath);
return new OnlineEmailDownloader(dialogue, attachmentsPath, dbPath, strTmpPath);
}
项目:DEM
文件:OnlineEmailDownloader.java
public OnlineEmailDownloader(EmailDownloaderDialog dialogue,
String attachmentsPath, String dbPath, String strTmpPath) throws SQLException, NoSuchProviderException, MessagingException, IOException {
this.attachmentsPath = attachmentsPath;
this.emaildialogue = dialogue;
this.dbPath = dbPath;
this.m_bPause = false;
this.m_strTmpPath = strTmpPath;
objResume = new ResumeState();
// if(true) objResume.Activate();
System.setProperty("mail.mime.address.strict", "false");
System.setProperty("mail.mimi.decodefilename", "true");
System.setProperty("mail.mimi.base64.ignoreerros", "true");
System.setProperty("mail.mime.multipart.ignorewhitespaceline", "true");
System.setProperty("mail.mime.parameters.strict", "false");
System.setProperty("mail.mime.setdefaulttextcharse", "true");
FileUtil.createFolder(attachmentsPath);
this.emaildialogue.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
cancel(true);
}
});
emaildialogue.getCancelButton().setEnabled(false);
}