标签: gmail-api

如何在Gmail中获取完整的邮件正文?

我想获得完整的消息体.所以我尝试:

Message gmailMessage = service.users().messages().get("me", messageId).setFormat("full").execute();
Run Code Online (Sandbox Code Playgroud)

为了获得身体,我尝试:

gmailMessage.getPayload().getBody().getData()
Run Code Online (Sandbox Code Playgroud)

但结果总是如此null.如何获得完整的邮件正文?

java gmail gmail-api

14
推荐指数
5
解决办法
2万
查看次数

不推荐使用NSURLConnection initWithRequest

我在iOS中采用了Gmail API,我收到了警告:

不推荐使用initWithRequest

在以下行中:

connection_ = [[connectionClass alloc] initWithRequest:request_ delegate:self startImmediately:NO];
Run Code Online (Sandbox Code Playgroud)

该行位于API库的源文件GTMHTTPFetcher.m中.

弃用-initWithRequest:方法的替代品是什么?

ios gmail-api xcode7

14
推荐指数
3
解决办法
2万
查看次数

用于在Node.js中发送邮件的Gmail API

免责声明:

  • 我已经关注了Google自己的Node.js快速入门指南,并成功连接并使用了该 gmail.users.labels.list()功能.
  • 我在这里检查了问题/答案,就像这个(不是使用我询问的Node.js API),或者这个(类似于这个),这显然是我遇到的同样的问题,但解决方案没有工作.

我的问题:

使用Google的Node.js API时,尝试发送电子邮件时出错.错误是:

{
    "code": 403,
    "errors": [{
        "domain": "global",
        "reason": "insufficientPermissions",
        "message": "Insufficient Permission"
    }]
}
Run Code Online (Sandbox Code Playgroud)

我的设置:

fs.readFile(secretlocation, function processClientSecrets(err, content) {
    if (err) {
        console.log('Error loading client secret file: ' + err);
        return;
    }
    authorize(JSON.parse(content), sendMessage);
});

function sendMessage(auth) {
    var raw = makeBody('myrealmail@gmail.com', 'myrealmail@gmail.com', 'subject', 'message test');
    gmail.users.messages.send({
        auth: auth,
        userId: 'me',
        message: {
            raw: raw
        }
    }, function(err, response) { …
Run Code Online (Sandbox Code Playgroud)

node.js google-api-nodejs-client gmail-api

14
推荐指数
2
解决办法
1万
查看次数

尝试通过服务帐户发送电子邮件,获取com.google.api.client.auth.oauth2.TokenResponseException:401 Unauthorized

我有一个Google Apps帐户.我正在尝试使用服务帐户代表用户发送电子邮件.

我已经浏览了互联网,没有任何工作,我几乎不知所措.

我跟着Java指南,我仍然继续 com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized

为什么这段代码片段给我401 Unauthorized?

JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

            GoogleCredential credential = new GoogleCredential.Builder()
                    .setTransport(httpTransport)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId("something@something-something.iam.gserviceaccount.com")
                    .setServiceAccountPrivateKeyFromP12File(new File("path/to/file/myProject.p12"))
                    .setServiceAccountScopes(GmailScopes.all())
                    .setServiceAccountUser("user@mydomain.org")
                    .build();

Gmail gmailService = new Gmail.Builder(httpTransport, JSON_FACTORY, credential)
                    .setApplicationName("My App") // DOES IT MATTER WHAT THIS IS SET TO?
                    .build();

MimeMessage mimeMessage = createEmail("myemail@gmail.com", "user@mydomain.org", "Testing", "hey");
sendMessage(gmailService, "me", mimeMessage);
Run Code Online (Sandbox Code Playgroud)

这些方法基本上是从Googles文档中复制/粘贴的:

/**
     * Create a MimeMessage using the parameters provided.
     *
     * @param to email address of the receiver
     * @param …
Run Code Online (Sandbox Code Playgroud)

authentication oauth google-api google-apps gmail-api

14
推荐指数
1
解决办法
821
查看次数

Gmail邮件ID或ThreadId如何映射到新的Gmail用户界面?

编辑:解决下面的第一条评论,为清楚起见,这不是代码问题.问题很简单:

我应该在新的Gmail用户界面的URI查询字符串中添加什么来查看Gmail API创建的草稿邮件?

尽管这不是一个代码问题,但我要求Stack Overflow作为Google首选的Gmail API问题平台.

-

如果我在新的Gmail用户界面中查看草稿邮件,则URI如下所示:

https://mail.google.com/mail/u/1/?zx=iij9apqgzdf4#drafts?compose=jrjtXSqXwlFGnSGCQgDCdnHGVFdlpFMgzsCNgpQstQLxdLCMkjKstBmWZkCmjhWTQnpsZCJF

我看不到通过Gmail API创建的邮件的ID或ThreadId创建此类链接的任何方法.

以前,人们可以这样做:

https://mail.google.com/mail/u/1/?zx=ov61dxfbrcga#drafts?compose=1631caae9dbb074d

其中"compose"的值是Id.

如何在新UI中完成同样的事情?

gmail gmail-api

14
推荐指数
2
解决办法
1754
查看次数

javax.net.ssl.SSLHandshakeException:没有适当的协议(协议已禁用或密码套件不合适

我知道有几个关于此错误的问题,但没有任何对我有帮助。我有在 gmail 服务器上发送带有附件的电子邮件的方法,效果很好。昨天我买了一台新的 mac mini m1。我尝试用这种方法发送电子邮件,但它引发了此错误

 public static void sentEmail(String report){  
    BaseTest base = new BaseTest();
    
      
      String to = base.getProps().getProperty("emailTO"); ;//change accordingly  
      final String user = base.getProps().getProperty("emailFROM");//change accordingly  
      final String password = base.getProps().getProperty("emailPassword");//change accordingly  
       
      //1) get the session object     
      Properties properties = System.getProperties();  
      properties.setProperty("mail.smtp.host", "smtp.gmail.com");  
      properties.put("mail.smtp.auth", "true"); 
      properties.put("mail.smtp.port", "587");  
      properties.put("mail.smtp.starttls.enable", "true");
      
      
      Session session = Session.getDefaultInstance(properties,  
       new javax.mail.Authenticator() {  
       protected PasswordAuthentication getPasswordAuthentication() {  
       return new PasswordAuthentication(user,password);  
       }  
      });  
         
      //2) compose message     
      try{  
        MimeMessage message = new MimeMessage(session);  
        message.setFrom(new InternetAddress(user));  
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to)); …
Run Code Online (Sandbox Code Playgroud)

java smtp gmail-api

14
推荐指数
2
解决办法
4万
查看次数

使用Gmail API发送带有签名的电子邮件

我将Gmail Rest API发送部分工作但电子邮件不包含签名,而在收件人的收件箱中,"发件人"标签是发件人的用户ID,而不是用户的名称.

这是在PHP中.

    $mime = new Mail_mime();
    $mime->setFrom("ABCD");  //This doesn't work....
    $mime->setSubject('Testing');
    $mime->setTXTBody('This is a demo mail');
    $mime->addTo('a@a.com');
    $message_body = $mime->getMessage();
    $encodeMessage = base64url_encode($message_body);
    $message = new Google_Service_Gmail_Message();
    $message->setRaw($encodeMessage);
    $send = $service->users_messages->send('me', $message);
Run Code Online (Sandbox Code Playgroud)

反正是否包含签名并更改'from'?

php gmail-api

13
推荐指数
1
解决办法
2469
查看次数

Gmail API配置问题(使用Java)

这是我的Gmail服务配置/工厂类:

import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.GmailScopes;

public class GmailServiceFactoryBean {

    private @Autowired Environment env;

    private final NetHttpTransport transport;
    private final JacksonFactory jacksonFactory;

    public GmailServiceFactoryBean() throws GeneralSecurityException, IOException {
        this.transport = GoogleNetHttpTransport.newTrustedTransport();
        this.jacksonFactory = JacksonFactory.getDefaultInstance();
    }

    public Gmail getGmailService() throws IOException, GeneralSecurityException {
        return new Gmail.Builder(transport, jacksonFactory, getCredential())
                .setApplicationName(env.getProperty("gmail.api.application.name")).build();
    }

    private HttpRequestInitializer getCredential() throws IOException, GeneralSecurityException {
        File p12File = …
Run Code Online (Sandbox Code Playgroud)

java configuration gmail spring gmail-api

13
推荐指数
1
解决办法
966
查看次数

使用Gmail发送附件R的电子邮件

我试图从我的系统附加一个文件,使用R将其发送到电子邮件ID.我正在使用gmailr包发送邮件.我尝试了以下代码.

library(gmailr)

mime() %>%
to("abcd@gmail.com") %>%
from("xyz@gmail.com") %>%
text_body("My First Email using R.") -> first_part

first_part %>%
subject("Test Mail from R") %>%
attach_file("BazaarQueriesforURLData.txt") -> file_attachment

send_message(file_attachment)
Run Code Online (Sandbox Code Playgroud)

我已经能够发送基于文本的消息,但我无法从R发送附件.我的附件只在默认目录文件夹中.我在互联网上看到了很多解决方案但我无法找到解决方案.

我希望有一个具有正确的OAuth或基于Json的身份验证的解决方案,因为Google阻止了我尝试使用基于smtp的身份验证.

email r gmail-api

13
推荐指数
1
解决办法
2573
查看次数

使用Gmail API发送的邮件中缺少附件,但仅适用于收件人

在Javascript中使用Gmail API发送带有HTML正文和~100KB PDF附件的邮件时,附件会正确显示在发件人的Gmail已发送文件夹中的邮件中,但不会显示在收件人的邮件中.

API调用是POST:

https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=media
Run Code Online (Sandbox Code Playgroud)

发送给API的请求正文是:

{
  "headers": {
    "Authorization": "Bearer authToken-removedForThisPost"
  },
  "method": "POST",
  "contentType": "message/rfc822",
  "contentLength": 134044,
  "payload": "exampleBelow",
  "muteHttpExceptions": true
}
Run Code Online (Sandbox Code Playgroud)

这是有效载荷的样子:

MIME-Version: 1.0
To: =?utf-8?B?TWlrZSBD?=<recipient@test.com>
CC: =?utf-8?B?TWlrZSBD?=<secondrecipient@gmail.com>
BCC: =?utf-8?B??=<bccrecipient@test.com>
From: =?utf-8?B?TWlrZSBxWXsd2lr?=<sender@test.com>
Subject: =?utf-8?B?subjectLine-removedForThisPost?=
Content-Type: multipart/alternative; boundary=__boundary__

--__boundary__
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64

base64EncodedStringHere-removedForThisPost

--__boundary__
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64

base64EncodedStringHere-removedForThisPost

--__boundary__
Content-Type: application/pdf; name="File Name.pdf"
Content-Disposition: attachment; filename="File Name.pdf"
Content-Transfer-Encoding: base64

base64EncodedStringHere-removedForThisPost

--__boundary__--
Run Code Online (Sandbox Code Playgroud)

注意:Gmail API上传附件文档指出,上传简单附件(5MB以下)时Content-Length需要.我做了它,以便我的代码生成PDF附件的总字节数的整数值.但是,我注意到它Content-Length没有包含在有效载荷中.

我尝试将multipart/alternative邮件的内容类型更改为 …

email gmail attachment email-attachments gmail-api

13
推荐指数
1
解决办法
1582
查看次数