本文整理汇总了Java中com.google.api.services.gmail.model.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于com.google.api.services.gmail.model包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performRequest
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private static void performRequest(String accessToken, String refreshToken, String apiKey, String apiSecret) throws GeneralSecurityException, IOException, MessagingException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
final Credential credential = convertToGoogleCredential(accessToken, refreshToken, apiSecret, apiKey);
Builder builder = new Gmail.Builder(httpTransport, jsonFactory, credential);
builder.setApplicationName("OAuth API Sample");
Gmail gmail = builder.build();
MimeMessage content = createEmail("[email protected]", "[email protected]", "Test Email", "It works");
Message message = createMessageWithEmail(content);
gmail.users().messages().send("[email protected]", message).execute();
}
示例2: createThreadedTestEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private Message createThreadedTestEmail(String previousThreadId) throws MessagingException, IOException {
com.google.api.services.gmail.model.Profile profile = requestBody("google-mail://users/getProfile?inBody=userId", CURRENT_USERID);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage mm = new MimeMessage(session);
mm.addRecipients(javax.mail.Message.RecipientType.TO, profile.getEmailAddress());
mm.setSubject("Hello from camel-google-mail");
mm.setContent("Camel rocks!", "text/plain");
Message createMessageWithEmail = createMessageWithEmail(mm);
if (previousThreadId != null) {
createMessageWithEmail.setThreadId(previousThreadId);
}
Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is com.google.api.services.gmail.model.Message
headers.put("CamelGoogleMail.content", createMessageWithEmail);
return requestBodyAndHeaders("google-mail://messages/send", null, headers);
}
示例3: createMessageWithEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private Message createMessageWithEmail(MimeMessage email) throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
email.writeTo(baos);
String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
示例4: testList
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
@Test
public void testList() throws Exception {
Message m1 = createThreadedTestEmail(null);
Message m2 = createThreadedTestEmail(m1.getThreadId());
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
// using String message body for single parameter "userId"
com.google.api.services.gmail.model.ListThreadsResponse result = requestBodyAndHeaders("direct://LIST", CURRENT_USERID, headers);
assertNotNull("list result", result);
assertTrue(result.getThreads().size() > 0);
LOG.debug("list: " + result);
headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", m1.getThreadId());
requestBodyAndHeaders("direct://DELETE", null, headers);
}
示例5: createEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
/**
* Create a MimeMessage using the parameters provided.
*
* @param to Email address of the receiver.
* @param from Email address of the sender, the mailbox account.
* @param subject Subject of the email.
* @param bodyText Body text of the email.
* @return MimeMessage to be used to send email.
* @throws MessagingException
*/
private static MimeMessage createEmail(String to, String from, String subject,
String bodyText) throws MessagingException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
InternetAddress tAddress = new InternetAddress(to);
InternetAddress fAddress = new InternetAddress(from);
email.setFrom(new InternetAddress(from));
email.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(to));
email.setSubject(subject);
email.setText(bodyText);
return email;
}
示例6: _createEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private static MimeMessage _createEmail(final String to,final String from,
final String subject,
final String bodyText) throws MessagingException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
InternetAddress toAddress = new InternetAddress(to);
InternetAddress fromAddress = new InternetAddress(from);
email.setFrom(fromAddress);
email.addRecipient(javax.mail.Message.RecipientType.TO,
toAddress);
email.setSubject(subject);
email.setText(bodyText);
return email;
}
示例7: sync
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
/**
* Synchronizes the given list of messages with Gmail. When this operation
* completes, all of the messages will appear in Gmail with the same labels
* (folers) that they have in the local store. The message state, including
* read/unread, will also be synchronized, but might not match exactly if
* the message is already in Gmail.
*
* <p>Note that some errors can prevent some messages from being uploaded.
* In this case, the failure policy dictates what happens.
*
* @param messages the list of messages to synchronize. These messages may
* or may not already exist in Gmail.
* @throws IOException if something goes wrong with the connection
*/
public void sync(List<LocalMessage> messages) throws IOException {
Preconditions.checkState(initialized,
"GmailSyncer.init() must be called first");
Multimap<LocalMessage, Message> map = mailbox.mapMessageIds(messages);
messages.stream()
.filter(message -> !map.containsKey(message))
.forEach(message -> {
try {
Message gmailMessage = mailbox.uploadMessage(message);
map.put(message, gmailMessage);
} catch (GoogleJsonResponseException e) {
// Message couldn't be uploaded, but we know why
}
});
mailbox.fetchExistingLabels(map.values());
mailbox.syncLocalLabelsToGmail(map);
}
示例8: createMessage
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private static Message createMessage(ProducerTemplate template, String subject)
throws MessagingException, IOException {
Profile profile = template.requestBody("google-mail://users/getProfile?inBody=userId", CURRENT_USERID,
Profile.class);
Session session = Session.getDefaultInstance(new Properties(), null);
MimeMessage mm = new MimeMessage(session);
mm.addRecipients(javax.mail.Message.RecipientType.TO, profile.getEmailAddress());
mm.setSubject(subject);
mm.setContent("Camel rocks!\n" //
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()) + "\n" //
+ "user: " + System.getProperty("user.name"), "text/plain");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mm.writeTo(baos);
String encodedEmail = Base64.getUrlEncoder().encodeToString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
示例9: createEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private static MimeMessage createEmail(String to, String from, String subject, String bodyText) throws MessagingException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
email.setFrom(new InternetAddress(from));
email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
email.setSubject(subject);
email.setText(bodyText);
return email;
}
示例10: createMessageWithEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
private static Message createMessageWithEmail(MimeMessage emailContent) throws IOException, MessagingException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
emailContent.writeTo(buffer);
byte[] bytes = buffer.toByteArray();
String encodedEmail = Base64.encodeBase64URLSafeString(bytes);
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
示例11: createEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
public static MimeMessage createEmail(String to, String from, String subject,
String bodyText) throws MessagingException{
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
InternetAddress tAddress = new InternetAddress(to);
InternetAddress fAddress = new InternetAddress(from);
email.setFrom(fAddress);
email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
email.setSubject(subject);
email.setText(bodyText);
return email;
}
示例12: createEmailWithAttachment
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
public static MimeMessage createEmailWithAttachment(String to, String from, String subject,
String bodyText,String filePath) throws MessagingException{
File file = new File(filePath);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
Multipart multipart = new MimeMultipart();
InternetAddress tAddress = new InternetAddress(to);
InternetAddress fAddress = new InternetAddress(from);
email.setFrom(fAddress);
email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
email.setSubject(subject);
if (file.exists()) {
source = new FileDataSource(filePath);
messageFilePart = new MimeBodyPart();
messageBodyPart = new MimeBodyPart();
try {
messageBodyPart.setText(bodyText);
messageFilePart.setDataHandler(new DataHandler(source));
messageFilePart.setFileName(file.getName());
multipart.addBodyPart(messageBodyPart);
multipart.addBodyPart(messageFilePart);
email.setContent(multipart);
} catch (MessagingException e) {
e.printStackTrace();
}
}else
email.setText(bodyText);
return email;
}
示例13: createMessageWithEmail
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
public static Message createMessageWithEmail(MimeMessage email)
throws MessagingException, IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
email.writeTo(bytes);
String encodedEmail = Base64.encodeToString(bytes.toByteArray(), Base64.URL_SAFE);
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
示例14: getMessageByMailId
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
public Message getMessageByMailId(final String mailId) throws IOException, MessageNotFoundException {
try {
return gmail().users().messages().get(me(), mailId)
.setQuotaUser(getCurrentUserId())
.setPrettyPrint(shouldBePretty())
.execute();
} catch (GoogleJsonResponseException e) {
if (e.getDetails().getCode() == HttpServletResponse.SC_NOT_FOUND) {
throw new MessageNotFoundException();
} else {
throw e;
}
}
}
示例15: process
import com.google.api.services.gmail.model.Message; //导入依赖的package包/类
public void process(final String mailId, final List<String> options) throws
IOException,
WasAnsweredButNoAnswerOptionWasGivenException,
MessageNotFoundException,
ScheduledLabelWasRemovedException {
final Message messageToBeProcessed = getMessageByMailId(mailId);
final boolean stillHasScheduledLabel = messageHasScheduledLabel(messageToBeProcessed);
if (!stillHasScheduledLabel) {
throw new ScheduledLabelWasRemovedException();
}
if (options.contains(ProcessingOptions.ONLY_IF_NO_ANSWER)) {
final boolean isLastMessageInThread = isLastMessageInThread(messageToBeProcessed);
if (!isLastMessageInThread) {
throw new WasAnsweredButNoAnswerOptionWasGivenException();
}
}
final List<String> addLabelIds = new ArrayList<String>(4);
addLabelIds.add(getBaseLabel().getId());
if (options.contains(ProcessingOptions.MARK_UNREAD)) {
addLabelIds.add(LABEL_ID_UNREAD);
}
if (options.contains(ProcessingOptions.MOVE_TO_INBOX)) {
addLabelIds.add(LABEL_ID_INBOX);
}
if (options.contains(ProcessingOptions.STAR)) {
addLabelIds.add(LABEL_ID_STARRED);
}
final ModifyMessageRequest mmr = new ModifyMessageRequest()
.setAddLabelIds(addLabelIds)
.setRemoveLabelIds(Collections.singletonList(getScheduledLabel().getId()));
gmail().users().messages().modify(me(), mailId, mmr)
.setQuotaUser(getCurrentUserId())
.setPrettyPrint(shouldBePretty())
.execute();
}