本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}