com.google.api.services.gmail.Gmail类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(14.4k)|赞(0)|评价(0)|浏览(694)

本文整理了Java中com.google.api.services.gmail.Gmail类的一些代码示例,展示了Gmail类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gmail类的具体详情如下:
包路径:com.google.api.services.gmail.Gmail
类名称:Gmail

Gmail介绍

[英]Service definition for Gmail (v1).

Access Gmail mailboxes including sending user email.

For more information about this service, see the API Documentation

This service uses GmailRequestInitializer to initialize global parameters via its Builder.
[中]

代码示例

代码示例来源:origin: stackoverflow.com

service.users().messages().send("me", m).execute();

代码示例来源:origin: google/mail-importer

BatchRequest batchRequest = gmailApi.batch();
for (String label : missingLabels) {
 System.err.format("Adding label %s\n", label);
 gmailApi.users()
   .labels()
   .create(user.getEmailAddress(), new Label()

代码示例来源:origin: com.google.apis/google-api-services-gmail

/**
 * Creates a new draft with the DRAFT label.
 *
 * Create a request for the method "drafts.create".
 *
 * This request holds the parameters needed by the the gmail server.  After setting any optional
 * parameters, call the {@link Create#execute()} method to invoke the remote operation. <p> {@link
 * Create#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must
 * be called to initialize this instance immediately after invoking the constructor. </p>
 *
 * <p>
 * This constructor should be used for uploading media content.
 * </p>
 *
 * @param userId The user's email address. The special value me can be used to indicate the authenticated user.
*        [default: me]
 * @param content the {@link com.google.api.services.gmail.model.Draft} media metadata or {@code null} if none
 * @param mediaContent The media HTTP content or {@code null} if none.
 * @since 1.13
 */
protected Create(java.lang.String userId, com.google.api.services.gmail.model.Draft content, com.google.api.client.http.AbstractInputStreamContent mediaContent) {
 super(Gmail.this, "POST", "/upload/" + getServicePath() + REST_PATH, content, com.google.api.services.gmail.model.Draft.class);
 this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified.");
 initializeMediaUpload(mediaContent);
}

代码示例来源:origin: com.google.apis/google-api-services-gmail

/** Builds a new instance of {@link Gmail}. */
@Override
public Gmail build() {
 return new Gmail(this);
}

代码示例来源:origin: google/mail-importer

batches.thisBatch = gmail.batch();
batches.nextBatch = gmail.batch();
    .collect(toList());
  Gmail.Users.Messages.Modify request = gmail.users()
    .messages()
    .modify(user.getEmailAddress(), message.getId(),
  batches.thisBatch.execute();
  batches.thisBatch = batches.nextBatch;
  batches.nextBatch = gmail.batch();

代码示例来源:origin: com.google.apis/google-api-services-gmail

/**
 * Imports a message into only this user's mailbox, with standard email delivery scanning and
 * classification similar to receiving via SMTP. Does not send a message.
 *
 * Create a request for the method "messages.import".
 *
 * This request holds the parameters needed by the the gmail server.  After setting any optional
 * parameters, call the {@link GmailImport#execute()} method to invoke the remote operation. <p>
 * {@link
 * GmailImport#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)}
 * must be called to initialize this instance immediately after invoking the constructor. </p>
 *
 * <p>
 * This constructor should be used for uploading media content.
 * </p>
 *
 * @param userId The user's email address. The special value me can be used to indicate the authenticated user.
*        [default: me]
 * @param content the {@link com.google.api.services.gmail.model.Message} media metadata or {@code null} if none
 * @param mediaContent The media HTTP content or {@code null} if none.
 * @since 1.13
 */
protected GmailImport(java.lang.String userId, com.google.api.services.gmail.model.Message content, com.google.api.client.http.AbstractInputStreamContent mediaContent) {
 super(Gmail.this, "POST", "/upload/" + getServicePath() + REST_PATH, content, com.google.api.services.gmail.model.Message.class);
 this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified.");
 initializeMediaUpload(mediaContent);
}

代码示例来源:origin: google/data-transfer-project

@Override
 public Map<String, String> get() {
  ListLabelsResponse response = null;
  try {
   response = getOrCreateGmail(authData).users().labels().list(USER).execute();
  } catch (IOException e) {
   throw new RuntimeException("Unable to list labels for user", e);
  }
  ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
  for (Label label : response.getLabels()) {
   // TODO: remove system labels
   builder.put(label.getName(), label.getId());
  }
  return builder.build();
 }
};

代码示例来源:origin: google/mail-importer

Multimap<LocalMessage, Message> localMessageToGmailMessages)
 throws IOException {
BatchRequest relabelBatch = gmailApi.batch();
for (Map.Entry<LocalMessage, Message> entry
  : localMessageToGmailMessages.entries()) {
       .collect(Collectors.joining(", ")),
     gmailMessage.getId());
   gmailApi.users().messages().modify(
     user.getEmailAddress(),
     gmailMessage.getId(),

代码示例来源:origin: com.google.apis/google-api-services-gmail

/**
 * Sends the specified message to the recipients in the To, Cc, and Bcc headers.
 *
 * Create a request for the method "messages.send".
 *
 * This request holds the parameters needed by the the gmail server.  After setting any optional
 * parameters, call the {@link Send#execute()} method to invoke the remote operation. <p> {@link
 * Send#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must be
 * called to initialize this instance immediately after invoking the constructor. </p>
 *
 * <p>
 * This constructor should be used for uploading media content.
 * </p>
 *
 * @param userId The user's email address. The special value me can be used to indicate the authenticated user.
*        [default: me]
 * @param content the {@link com.google.api.services.gmail.model.Message} media metadata or {@code null} if none
 * @param mediaContent The media HTTP content or {@code null} if none.
 * @since 1.13
 */
protected Send(java.lang.String userId, com.google.api.services.gmail.model.Message content, com.google.api.client.http.AbstractInputStreamContent mediaContent) {
 super(Gmail.this, "POST", "/upload/" + getServicePath() + REST_PATH, content, com.google.api.services.gmail.model.Message.class);
 this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified.");
 initializeMediaUpload(mediaContent);
}

代码示例来源:origin: google/data-transfer-project

@Before
public void setup() throws IOException {
 googleMailExporter = new GoogleMailExporter(googleCredentialFactory, gmail);
 when(gmail.users()).thenReturn(users);
 when(users.messages()).thenReturn(messages);
 when(messages.list(Matchers.anyString())).thenReturn(messageListRequest);
 when(messageListRequest.setMaxResults(Matchers.anyLong())).thenReturn(messageListRequest);
 when(messages.get(Matchers.anyString(), Matchers.anyString())).thenReturn(get);
 when(get.setFormat(Matchers.anyString())).thenReturn(get);
 verifyZeroInteractions(googleCredentialFactory);
}

代码示例来源:origin: google/mail-importer

void fetchExistingLabels(Iterable<Message> messages) {
 Gmail gmail = gmailService.getServiceWithRetries();
 BatchRequest batch = gmail.batch();
   gmail.users().messages().get(user.getEmailAddress(), message.getId())
     .setFields("id,labelIds")
     .queue(batch, new JsonBatchCallback<Message>() {

代码示例来源:origin: com.google.apis/google-api-services-gmail

/**
 * Sends the specified, existing draft to the recipients in the To, Cc, and Bcc headers.
 *
 * Create a request for the method "drafts.send".
 *
 * This request holds the parameters needed by the the gmail server.  After setting any optional
 * parameters, call the {@link Send#execute()} method to invoke the remote operation. <p> {@link
 * Send#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must be
 * called to initialize this instance immediately after invoking the constructor. </p>
 *
 * <p>
 * This constructor should be used for uploading media content.
 * </p>
 *
 * @param userId The user's email address. The special value me can be used to indicate the authenticated user.
*        [default: me]
 * @param content the {@link com.google.api.services.gmail.model.Draft} media metadata or {@code null} if none
 * @param mediaContent The media HTTP content or {@code null} if none.
 * @since 1.13
 */
protected Send(java.lang.String userId, com.google.api.services.gmail.model.Draft content, com.google.api.client.http.AbstractInputStreamContent mediaContent) {
 super(Gmail.this, "POST", "/upload/" + getServicePath() + REST_PATH, content, com.google.api.services.gmail.model.Message.class);
 this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified.");
 initializeMediaUpload(mediaContent);
}

代码示例来源:origin: google/data-transfer-project

@Before
public void setUp() throws IOException {
 Label label = new Label();
 label.setId(LABEL1);
 label.setName(LABEL1);
 labelsListResponse = new ListLabelsResponse().setLabels(Collections.singletonList(label));
 jobStore = new LocalJobStore();
 Monitor monitor = new Monitor() {};
 googleMailImporter = new GoogleMailImporter(googleCredentialFactory, jobStore, gmail, monitor);
 when(gmail.users()).thenReturn(users);
 when(users.messages()).thenReturn(messages);
 when(messages.insert(Matchers.anyString(), Matchers.any(Message.class))).thenReturn(insert);
 when(users.labels()).thenReturn(labels);
 when(labels.list(Matchers.anyString())).thenReturn(labelsList);
 when(labelsList.execute()).thenReturn(labelsListResponse);
 when(labels.create(Matchers.anyString(), Matchers.any(Label.class))).thenReturn(labelsCreate);
 when(labelsCreate.execute()).thenReturn(label);
 verifyZeroInteractions(googleCredentialFactory);
}

代码示例来源:origin: google/mail-importer

BatchRequest batch = gmail.batch();
  gmail.users().messages().list(user.getEmailAddress())
    .setQ("rfc822msgid:" + localMessage.getMessageId())
    .setFields("messages(id)")

代码示例来源:origin: com.google.apis/google-api-services-gmail

/**
 * Directly inserts a message into only this user's mailbox similar to IMAP APPEND, bypassing most
 * scanning and classification. Does not send a message.
 *
 * Create a request for the method "messages.insert".
 *
 * This request holds the parameters needed by the the gmail server.  After setting any optional
 * parameters, call the {@link Insert#execute()} method to invoke the remote operation. <p> {@link
 * Insert#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must
 * be called to initialize this instance immediately after invoking the constructor. </p>
 *
 * <p>
 * This constructor should be used for uploading media content.
 * </p>
 *
 * @param userId The user's email address. The special value me can be used to indicate the authenticated user.
*        [default: me]
 * @param content the {@link com.google.api.services.gmail.model.Message} media metadata or {@code null} if none
 * @param mediaContent The media HTTP content or {@code null} if none.
 * @since 1.13
 */
protected Insert(java.lang.String userId, com.google.api.services.gmail.model.Message content, com.google.api.client.http.AbstractInputStreamContent mediaContent) {
 super(Gmail.this, "POST", "/upload/" + getServicePath() + REST_PATH, content, com.google.api.services.gmail.model.Message.class);
 this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified.");
 initializeMediaUpload(mediaContent);
}

代码示例来源:origin: google/data-transfer-project

.setLabelIds(importedLabelIds.build());
try {
 getOrCreateGmail(authData).users().messages().insert(USER, newMessage).execute();
} catch (IOException e) {
 return new ImportResult(e);

代码示例来源:origin: com.google.apis/google-api-services-gmail

/**
 * Replaces a draft's content.
 *
 * Create a request for the method "drafts.update".
 *
 * This request holds the parameters needed by the the gmail server.  After setting any optional
 * parameters, call the {@link Update#execute()} method to invoke the remote operation. <p> {@link
 * Update#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must
 * be called to initialize this instance immediately after invoking the constructor. </p>
 *
 * <p>
 * This constructor should be used for uploading media content.
 * </p>
 *
 * @param userId The user's email address. The special value me can be used to indicate the authenticated user.
*        [default: me]@param id The ID of the draft to update.
 * @param content the {@link com.google.api.services.gmail.model.Draft} media metadata or {@code null} if none
 * @param mediaContent The media HTTP content or {@code null} if none.
 * @since 1.13
 */
protected Update(java.lang.String userId, java.lang.String id, com.google.api.services.gmail.model.Draft content, com.google.api.client.http.AbstractInputStreamContent mediaContent) {
 super(Gmail.this, "PUT", "/upload/" + getServicePath() + REST_PATH, content, com.google.api.services.gmail.model.Draft.class);
 this.userId = com.google.api.client.util.Preconditions.checkNotNull(userId, "Required parameter userId must be specified.");
 this.id = com.google.api.client.util.Preconditions.checkNotNull(id, "Required parameter id must be specified.");
 initializeMediaUpload(mediaContent);
}

代码示例来源:origin: google/data-transfer-project

/** Creates the given {@code labelName} in the import service provider and returns the id. */
private String createImportedLabelId(TokensAndUrlAuthData authData, String labelName)
  throws IOException {
 Label newLabel =
   new Label()
     .setName(labelName)
     .setLabelListVisibility("labelShow")
     .setMessageListVisibility("show");
 return getOrCreateGmail(authData).users().labels().create(USER, newLabel).execute().getId();
}

代码示例来源:origin: google/data-transfer-project

request = gmail.users().messages().list(USER).setMaxResults(PAGE_SIZE);
} catch (IOException e) {
 return new ExportResult<>(e);
 try {
  getResponse =
    gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute();
 } catch (IOException e) {
  return new ExportResult<>(e);

代码示例来源:origin: magefree/mage

public static boolean sendMessage(String email, String subject, String text) {
    if (email.isEmpty()) {
      logger.info("Email is not sent because the address is empty");
      return false;
    }
    try {
      Gmail gmail = new Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("XMage Server").build();

      MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
      mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email));
      mimeMessage.setSubject(subject);
      mimeMessage.setText(text);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      mimeMessage.writeTo(baos);
      Message message = new Message();
      message.setRaw(Base64.encodeBase64URLSafeString(baos.toByteArray()));

      gmail.users().messages().send(ConfigSettings.instance.getGoogleAccount()
          + (ConfigSettings.instance.getGoogleAccount().endsWith("@gmail.com") ? "" : "@gmail.com"), message).execute();
      return true;
    } catch (MessagingException | IOException ex) {
      logger.error("Error sending message", ex);
    }
    return false;
  }
}

相关文章

Gmail类方法