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


Java Gmail类代码示例

本文整理汇总了Java中com.google.api.services.gmail.Gmail的典型用法代码示例。如果您正苦于以下问题:Java Gmail类的具体用法?Java Gmail怎么用?Java Gmail使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Gmail类属于com.google.api.services.gmail包,在下文中一共展示了Gmail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performRequest

import com.google.api.services.gmail.Gmail; //导入依赖的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();
}
 
开发者ID:tburne,项目名称:blog-examples,代码行数:12,代码来源:ClientRequestAPI.java

示例2: makeClient

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
@Override
public Gmail makeClient(String clientId, String clientSecret, Collection<String> scopes, String applicationName, String refreshToken, String accessToken) {
    Credential credential;
    try {
        credential = authorize(clientId, clientSecret, scopes);

        if (refreshToken != null && !"".equals(refreshToken)) {
            credential.setRefreshToken(refreshToken);
        }
        if (accessToken != null && !"".equals(accessToken)) {
            credential.setAccessToken(accessToken);
        }
        return new Gmail.Builder(transport, jsonFactory, credential).setApplicationName(applicationName).build();
    } catch (Exception e) {
        LOG.error("Could not create Google Drive client.", e);
    }
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:BatchGoogleMailClientFactory.java

示例3: getGmailService

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
private static Gmail getGmailService(String basedir, String appName) throws Exception {

        // 機密情報ファイルのパス
        File DATA_STORE_DIR = new java.io.File(basedir, "gmail-secrets");
        File SECRET_JSON = new java.io.File(DATA_STORE_DIR, "client_secret.json");

        // 準備
        FileDataStoreFactory DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
        HttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

        // 送信のみ
        List<String> SCOPES = Arrays.asList(GmailScopes.GMAIL_SEND);

        // Credential取得
        try (InputStream in = FileUtils.openInputStream(SECRET_JSON)) {
            GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
            GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
                    clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
            Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

            // Gmailインスタンス生成
            return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(appName).build();
        }
    }
 
开发者ID:af-not-found,项目名称:blog-java2,代码行数:26,代码来源:SmtpManager.java

示例4: startAuthentication

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
/**
 * Build and return an authorized Gmail client service.
 *
 * @return an authorized Gmail client service
 * @throws IOException
 */
public static void startAuthentication() throws IOException {
    Credential credential = authorize();
    service =  new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();
}
 
开发者ID:ashoknailwal,项目名称:desktop-gmail-client,代码行数:13,代码来源:Login.java

示例5: checkGmailApiRequirements

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
private void checkGmailApiRequirements() {


        String accountName = PreferenceManager.getDefaultSharedPreferences(getContext())
                .getString(PREF_ACCOUNT_NAME, null);

        if (accountName != null) {
            GoogleAccountCredential mCredential = GoogleAccountCredential.usingOAuth2(
                    getContext().getApplicationContext(), Arrays.asList(SCOPES))
                    .setBackOff(new ExponentialBackOff());
            mCredential.setSelectedAccountName(accountName);

            if (!DeviceUtils.isGooglePlayServicesAvailable(getContext())) {
                DeviceUtils.acquireGooglePlayServices(getContext());
            }
            else{
                mService = new Gmail.Builder(
                        AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), mCredential)
                        .setApplicationName(AppUtils.getApplicationName(getContext()))
                        .build();
                authorized = true;
            }


        } else {
            GmailAuthorizationActivity.setListener(this);
            getContext().startActivity(new Intent(getContext(), GmailAuthorizationActivity.class));
        }

    }
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:31,代码来源:BaseGmailProvider.java

示例6: sendGmailinBackground

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
public sendGmailinBackground(GoogleAccountCredential credential,int order){
    isSending=true;
    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    mService = new Gmail.Builder(
            transport, jsonFactory, credential)
            .setApplicationName(getActivity().getString(R.string.app_name))
            .build();
    this.order = order;
    Log.d("Email","Sending Created!");
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:12,代码来源:EmailShield.java

示例7: MakeRequestTask

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
MakeRequestTask(MainActivity activity, GoogleAccountCredential credential) {
    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    mService = new com.google.api.services.gmail.Gmail.Builder(
            transport, jsonFactory, credential)
            .setApplicationName(getResources().getString(R.string.app_name))
            .build();
    this.activity = activity;
}
 
开发者ID:androidmads,项目名称:JavaMailwithGmailApi,代码行数:10,代码来源:MainActivity.java

示例8: sendMessage

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
private String sendMessage(Gmail service,
                           String userId,
                           MimeMessage email)
        throws MessagingException, IOException {
    Message message = createMessageWithEmail(email);
    // GMail's official method to send email with oauth2.0
    message = service.users().messages().send(userId, message).execute();

    System.out.println("Message id: " + message.getId());
    System.out.println(message.toPrettyString());
    return message.getId();
}
 
开发者ID:androidmads,项目名称:JavaMailwithGmailApi,代码行数:13,代码来源:MainActivity.java

示例9: getClient

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
public Gmail getClient() {
    if (client == null) {
        client = getClientFactory().makeClient(configuration.getClientId(), configuration.getClientSecret(), configuration.getScopes(), configuration.getApplicationName(),
                configuration.getRefreshToken(), configuration.getAccessToken());
    }
    return client;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:GoogleMailComponent.java

示例10: getGmailService

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
/**
 * Build and return an authorized Gmail client service.
 * @return an authorized Gmail client service
 * @throws IOException
 */
private static Gmail getGmailService() throws IOException {
    Credential credential = authorize();
    return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();
}
 
开发者ID:kinneerc,项目名称:giv-planner,代码行数:12,代码来源:GmailAPI.java

示例11: sendEmail

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
public static void sendEmail(String to, String subject, String message){
  	
  	// Build a new authorized API client service.
      Gmail service;
try {
	service = getGmailService();


      // Print the labels in the user's account.
      String user = "me";
      
      try {
	MimeMessage mm =  createEmail(to, "[email protected]", subject,
		      message);
	
	sendMessage(service,user,mm);
	
} catch (MessagingException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
      
} catch (IOException e1) {
	// TODO Auto-generated catch block
	e1.printStackTrace();
}
  	
  }
 
开发者ID:kinneerc,项目名称:giv-planner,代码行数:29,代码来源:GmailAPI.java

示例12: main

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
      // Build a new authorized API client service.
      Gmail service = getGmailService();

      // Print the labels in the user's account.
      String user = "me";
      
      try {
	MimeMessage mm =  createEmail("[email protected]", "[email protected]", "Subject",
		      "The body of the message");
	
	sendMessage(service,user,mm);
	
} catch (MessagingException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
      
      
      /*
      ListLabelsResponse listResponse =
          service.users().labels().list(user).execute();
      List<Label> labels = listResponse.getLabels();
      if (labels.size() == 0) {
          System.out.println("No labels found.");
      } else {
          System.out.println("Labels:");
          for (Label label : labels) {
              System.out.printf("- %s\n", label.getName());
          }
      }
      */
  }
 
开发者ID:kinneerc,项目名称:giv-planner,代码行数:34,代码来源:GmailAPI.java

示例13: updateCredential

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
public void updateCredential(SharedPreferences prefs){
	credential = GoogleAccountCredential.usingOAuth2(
			getApplicationContext(), Arrays.asList(GMConstants.SCOPES))
			.setBackOff(new ExponentialBackOff())
			.setSelectedAccountName(prefs.getString(GMConstants.PREF_ACCOUNT_NAME, null));
	if(credential != null && credential.getSelectedAccount() != null) {
		gmailService = new com.google.api.services.gmail.Gmail.Builder(
				transport, jsonFactory, credential)
				.setApplicationName("Shortyz")
				.build();
	} else {
		gmailService = null;
	}
}
 
开发者ID:kebernet,项目名称:shortyz,代码行数:15,代码来源:ShortyzApplication.java

示例14: createGmailService

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
public static Gmail createGmailService(final HttpTransport httpTransport,
									   final JsonFactory jsonFactory,
									   final AppCode appCode,
									   final GoogleCredential credential) {
	// Create a new authorized Gmail API client
	Gmail gmailService = new Gmail.Builder(httpTransport,
									  	  jsonFactory,
									  	  credential)
								   .setApplicationName(appCode.asString())
								   .build();
	return gmailService;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:13,代码来源:GoogleAPI.java

示例15: _sendMessage

import com.google.api.services.gmail.Gmail; //导入依赖的package包/类
private static void _sendMessage(final Gmail service,
						     final String userId,
						     final MimeMessage email) throws MessagingException,
						     								 IOException {
   Message message = _createMessageWithEmail(email);
   message = service.users()
   				 .messages()
   				 	.send(userId,message)
   				 	.execute();
   
   System.out.println("Message id: " + message.getId());
   System.out.println(message.toPrettyString());
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:14,代码来源:GMailAPITest.java


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