- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用不同的“角色”(例如 info@、customer-support@、tech-support@、no-reply@)向我的客户发送电子邮件。
我尝试了两种方法:
我首先为我的 Gmail for Business 应用程序设置一个具有全局授权的服务帐户。
为了测试它是否有效,我设置了 2 个用户:lev@mydomain.com 和 root@mydomain.com。事实上,我可以成功地从 lev@ 和 root@ 发送电子邮件。
但是,当我尝试为我的应用程序添加 5 个不同的用户帐户时,Gmail 对机器人/滥用感到偏执,并要求我证明所有帐户都是“人类”,包括通过设置密码、登录和短信验证电话。此外,他们要求不同的账户使用不同的手机来证明是不同的人。因此,账户的设置成为一个主要问题。
我还想避免创建多个帐户,因为我要为每个帐户付费,而且从语义上讲,所有角色都只是一个帐户。所以别名似乎是一个更好的主意。
问题是,当我尝试发送电子邮件并将“发件人”字段设置为别名(例如 from:no-reply@mydomain.com)时,出现以下异常:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Delegation denied for root@mydomain.com",
"reason" : "forbidden"
} ],
"message" : "Delegation denied for root@mydomain.com"
}
有人遇到并解决了这个问题吗?
身份验证/凭证代码如下:
/*
* Set up a hashmap HashMap<String, Gmail> gmailServiceByAccount where
* gmailServiceByAccount.get(emailAccount) contains an authorized Gmail service
*/
private void prepareService(String emailAccount) throws Exception {
if (gmailServiceByAccount.containsKey(emailAccount)) {
return;
}
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(Config.getInstance().getProperty(Config.gmail_service_account))
.setServiceAccountPrivateKeyFromP12File(new File(Config.getInstance().getPathToGmailCredential()))
.setServiceAccountScopes(Arrays.asList(GmailScopes.GMAIL_COMPOSE))
.setServiceAccountUser(emailAccount)
.build();
gmailServiceByAccount.put(
emailAccount,
new Gmail.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(Config.getInstance().getProperty(Config.google_client_api_application_name))
.build());
}
发送电子邮件的代码如下:
/**
* Send an email using the parameters provided.
*
* @param fromPersonalName : the free text description of the "from" address (e.g. "Customer Suppport" or "No Reply").
* @param fromAddress : the email address of the sender, the mailbox account (e.g. customer-support@mydomain.com).
* @param to : the email address of the recepient.
* @param subject : Subject of the email.
* @param htmlContent : (may be null) The HTML-styled body text of the email.
* @param plainTextContent : (may be null) The plain text body of the email (e.g if the customer email client does not support or disables html email).
*/
public void sendMail(String fromPersonalName, String fromAddress, String to, String subject, String htmlContent, String plainTextContent)
throws Exception {
prepareService(fromAddress);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
InternetAddress tAddress = new InternetAddress(to);
InternetAddress fAddress = new InternetAddress(fromAddress);
fAddress.setPersonal(fromPersonalName);
email.setFrom(fAddress);
email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
email.setSubject(subject);
Multipart multiPart = new MimeMultipart("alternative");
if (!StringValidation.isEmpty(plainTextContent)) {
MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(plainTextContent, "text/plain");
textPart.setHeader("Content-Type", "text/plain; charset=\"UTF-8\"");
multiPart.addBodyPart(textPart);
}
if (!StringValidation.isEmpty(htmlContent)) {
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlContent, "text/html; charset=\"UTF-8\"");
multiPart.addBodyPart(htmlPart);
}
email.setContent(multiPart);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
email.writeTo(bytes);
String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
gmailServiceByAccount.get(fromAddress).users().messages().send(fromAddress, message).execute();
}
最佳答案
经过额外研究,看起来唯一的选择是拥有多个用户。
我发布的代码确实适用于多个用户,但不适用于其他任何用户。
我尝试了多种选项,包括别名和群组电子邮件帐户。我要么收到“委托(delegate)被拒绝”或“无效授权”错误。
我已尝试联系 Google For Business 客户和技术支持,但他们不支持该 API。
有一个很好的解决方法可以创建多个用户,而无需通过电话验证。只需在您最初登录 Google For Business 时将这些用户指定为“现有用户”,并在转移域名之前激活它们即可。
对于我在没有预先存在的用户的情况下创建的帐户,我必须要求我 friend 的手机进行电话验证。
关于gmail-api - Gmail(企业版)API 不允许从 Alias 发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34348413/
我一直在积极跟进 Blazor,现在我想从我的工作场所获取一个企业应用程序,并将其转换为 Blazor,并保持在企业的限制范围内。我有很多问题,但我会重点关注:在托管方面我应该从什么模型开始。 ASP
destoon实现首页显示供应、企业、资讯条数有多种方法,这里介绍的是直接调用php程序代码进行查询。destoon的模板里面是支持php的代码的,因此我们可以直接在模板里面查询出来即可。 实现代
我目前的任务是为软件开发创建一个文档化的、一致的架构指南。我们有很多聪明人在做正确的事情,但只是不一致和可重复。 我们使用 Microsoft 的应用程序架构指南 2.0 作为起点。因此,提出一个应用
我们正在使用 Zeek 以“连接日志”的形式从交换机收集网络流量。然后,连接日志通过 filebeat 存储在 Elasticsearch 索引中。每个连接日志都是一个包含以下字段的元组:(sourc
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足 Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以
我只是研究Corda enterprise,我在解压这个文件时下载了文件Corda enterprise3.zip,里面有很多文件jar。谁能帮我解释下corda enterprise的运行和使用方法
我的Apple开发者帐户中有一些有关InHouse App(企业)的预配配置文件。 如果删除那些配置文件,会有什么影响? 会影响已发布的应用程序吗? 删除它安全吗? 最佳答案 您可以删除它们: 已安装
我有一个要分发给公司员工的 iOS 应用程序。我知道为此我们需要考虑企业开发者帐户。我的疑问是我将如何分发构建。苹果是否提供企业商店?如果不是假设我通过 diawi.com 或类似的服务分发构建,将如
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
是否需要注册测试设备(UDID)?在标准程序中,每个用户设备 ID 都必须添加到开发程序中,并且构建必须使用包含 ID 列表的正确配置文件进行签名。它在企业程序中的样子如何。 最佳答案 在企业中,您不
我在 Sphinx 中已有两个数据源: source cities { ... sql_query = SELECT id, city_name, state_name, state_
我们的企业应用程序的生产 APNs 证书即将到期。 是否只是为我们的应用程序 ID 创建新的生产 APNs 证书并用我们的推送通知提供商替换即将过期的证书? 我是否需要重新捆绑和重新分发我们的企业应用
我有一个关于企业 Mac 应用程序分发的问题。我已经使用企业分发证书签署了我的 mac 应用程序,该证书有效期为 future 三年。 现在我的问题是,安装在 Mac 操作系统上的应用程序是否会在三年
我有一个只能在纽约使用的应用程序,它已经在试飞中发布。我可以将其切换到企业版吗? 最佳答案 没有“开关”,它们是两个完全不同的进程。您需要创建一个新的 Enterprise account ,创建企业
对于在供大量人员使用的大型程序中使用缓存,我还比较陌生。我知道什么是缓存以及为什么它总体上是有益的,并且我已经开始将 EHCache 集成到我使用 JSP 和 Spring MVC 的应用程序中。在我
我的应用程序 ID(MDM 应用程序)的企业 APNS 本周过期,不幸的是我没有注意到它。所以我提出了一个新请求,开始在 APP ID 中为 APNS 创建证书,然后完成请求。我可以在我的 App I
我的任务是切换框架并选择 EF 作为 ORM,但我一直在努力弄清楚如何做到这一点。我了解 N 层的基础知识,但在我们公司,我们支持 15 个以上的应用程序,我想了解我们是否应该为每个项目提供单独的 .
我正在设计一个 MySQL 数据库和一个相应的 RoR 应用程序,用于保存各种业务,每个业务都有一个地址。 此应用程序的要求是按城市/国家/地区搜索数据库(这将适用于整个欧洲/英国的企业)。搜索结果将
当使用“企业分发”选项为客户分发 iOS 应用程序时,该应用程序会下载并安装,但很快就会从主屏幕上消失。重新启动 iOS 设备后,它会重新出现。 最佳答案 在我的情况下,如果您在要保存 .ipa 文件
为了让您了解一些背景知识,我们有一个任何人都可以通过网络访问的软件应用程序。它是银行业和零售业的一个非常具体的应用程序。目前,此应用程序可在 Web 和“Windows 平板电脑信息亭”上访问,我们有
我是一名优秀的程序员,十分优秀!