当前位置: 首页>>代码示例>>Java>>正文


Java SMTPTransport.issueCommand方法代码示例

本文整理汇总了Java中com.sun.mail.smtp.SMTPTransport.issueCommand方法的典型用法代码示例。如果您正苦于以下问题:Java SMTPTransport.issueCommand方法的具体用法?Java SMTPTransport.issueCommand怎么用?Java SMTPTransport.issueCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.mail.smtp.SMTPTransport的用法示例。


在下文中一共展示了SMTPTransport.issueCommand方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectToSmtp

import com.sun.mail.smtp.SMTPTransport; //导入方法依赖的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;
}
 
开发者ID:42cc,项目名称:p2psafety,代码行数:26,代码来源:GmailOAuth2Sender.java

示例2: connectToSmtp

import com.sun.mail.smtp.SMTPTransport; //导入方法依赖的package包/类
public SMTPTransport connectToSmtp(String userEmail, String oauthToken, Session session) throws Exception {
    final URLName unusedUrlName = null;
    SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
    final String emptyPassword = null;
    final String host = "smtp.gmail.com";
    final int port = 587;
    
    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;
}
 
开发者ID:nikablaine,项目名称:BatteryAlarm,代码行数:17,代码来源:BatteryStatePullService.java

示例3: connectToSmtp

import com.sun.mail.smtp.SMTPTransport; //导入方法依赖的package包/类
public SMTPTransport connectToSmtp(String userEmail, String oauthToken,
		Session session) throws Exception {
	final URLName unusedUrlName = null;
	SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
	final String emptyPassword = null;
	final String host = "smtp.gmail.com";
	final int port = 587;

	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;
}
 
开发者ID:nikablaine,项目名称:BatteryAlarm,代码行数:19,代码来源:Alarm.java

示例4: mailSenderEmpty

import com.sun.mail.smtp.SMTPTransport; //导入方法依赖的package包/类
@Test
public void mailSenderEmpty() throws IOException, MessagingException {
	Socket smtpSocket;
	String hostAddress = greenMail.getSmtp().getBindTo();
	int port = greenMail.getSmtp().getPort();

	Session smtpSession = greenMail.getSmtp().createSession();
	URLName smtpURL = new URLName(hostAddress);
	SMTPTransport smtpTransport = new SMTPTransport(smtpSession, smtpURL);

	try {
		smtpSocket = new Socket(hostAddress, port);
		smtpTransport.connect(smtpSocket);
		assertThat(smtpTransport.isConnected(),is(equalTo(true)));
		smtpTransport.issueCommand("MAIL FROM: <>", -1);
		assertThat("250 OK", equalToIgnoringWhiteSpace(smtpTransport.getLastServerResponse()));
	} finally {
		smtpTransport.close();
	}
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:21,代码来源:SMTPCommandTest.java

示例5: connectToSmtp

import com.sun.mail.smtp.SMTPTransport; //导入方法依赖的package包/类
private SMTPTransport connectToSmtp(Session session, String host, int port, String userEmail,
                                    String oauthToken) throws MessagingException {

    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;
}
 
开发者ID:peter-tackage,项目名称:open-secret-santa,代码行数:20,代码来源:GmailTransport.java

示例6: connectToSmtp

import com.sun.mail.smtp.SMTPTransport; //导入方法依赖的package包/类
/**
 * Connects and authenticates to an SMTP server with XOAUTH. 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 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 connection.
 *
 * @return An authenticated SMTPTransport that can be used for SMTP
 *     operations.
 */
public static SMTPTransport connectToSmtp(String host,
                                          int port,
                                          String userEmail,
                                          String oauthToken,
                                          String oauthTokenSecret,
                                          OAuthConsumer consumer,
                                          boolean debug) throws Exception {
  Properties props = new Properties();
  props.put("mail.smtp.ehlo", "true");
  props.put("mail.smtp.auth", "false");
  props.put("mail.smtp.starttls.enable", "true");
  props.put("mail.smtp.starttls.required", "true");
  props.put("mail.smtp.sasl.enable", "false");
  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 = null;
  transport.connect(host, port, userEmail, emptyPassword);

  /*
   * I couldn't get the SASL infrastructure to work with JavaMail 1.4.3;
   * I don't think it was ready yet in that release. So we'll construct the
   * AUTH command manually.
   */
  XoauthSaslResponseBuilder builder = new XoauthSaslResponseBuilder();
  byte[] saslResponse = builder.buildResponse(userEmail,
                                              XoauthProtocol.SMTP,
                                              oauthToken,
                                              oauthTokenSecret,
                                              consumer);
  saslResponse = BASE64EncoderStream.encode(saslResponse);
  transport.issueCommand("AUTH XOAUTH " + new String(saslResponse),
                         235);
  return transport;
}
 
开发者ID:google,项目名称:gmail-oauth2-tools,代码行数:57,代码来源:XoauthAuthenticator.java


注:本文中的com.sun.mail.smtp.SMTPTransport.issueCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。