我正在尝试使用sap commerce发送电子邮件。配置扩展名的local.properties我已经配置好了
mail.smtp.server=smtp.gmail.com
mail.smtp.host=smtp.gmail.com
mail.smtp.port=587
mail.from=sapcommerce14@gmail.com
mail.smtp.ssl.protocols=TLSv1.2
mail.smtp.user=sapcommerce14@gmail.com
mail.smtp.password=********
mail.smtp.starttls.enable=true
mail.smtp.auth=true
但在执行作业后以及发送电子邮件时,将显示警告
警告[TaskExecutor-master-1591-ProcessTask [8796754772918]]
[DefaultEmailService]无法发送电子邮件pk [8796226197568]主题[独家促销我们的产品-不要错过!!]原因:向以下服务器发送邮件失败:smtp.gmail.com:587
以下是我的工作步骤
1.我创建了一个“ListFavoritesProcess”模型,它扩展了“StoreFrontCustomerProcess”,并带有一个属性
<attribute qualifier="products" type="ProductList">
<persistence type="property" />
<description>Attribute contains the products that will be used in the process</description>
</attribute>
1.然后创建process.xml文件
1.然后我创建了一个类来启动这个过程
public Boolean discountNotificationEmailprocess(final CustomerModel customer, final Set<ProductModel> products)
{
Boolean bool = false;
if ((customer != null) && CollectionUtils.isNotEmpty(products))
{
final ListFavoritesProcessModel listFavoritesProcessModel = getBusinessProcessService()
.createProcess("listFavoritesProcessModel-" + customer.getUid() + "-"System.currentTimeMillis() + "-"+ Thread.currentThread().getId(), "DiscountNotificationEmailProcess");
listFavoritesProcessModel.setCustomer(customer);
listFavoritesProcessModel.setStore(getBaseStoreService().getBaseStoreForUid("electronics"));
listFavoritesProcessModel.setSite(getBaseSiteService().getBaseSiteForUID("electronics"));
listFavoritesProcessModel.setLanguage(getBaseStoreService().getBaseStoreForUid("electronics").getDefaultLanguage());
listFavoritesProcessModel.setCurrency(getBaseStoreService().getBaseStoreForUid("electronics").getDefaultCurrency());
listFavoritesProcessModel.setProducts(new ArrayList<ProductModel>(products));
getModelService().save(listFavoritesProcessModel);
getBusinessProcessService().startProcess(listFavoritesProcessModel);
bool = true;
}
return bool;
}
1.然后我创建了从AbstractEmailContext扩展的上下文
@Override
public void init(final ListFavoritesProcessModel listFavoritesProcessModel, final EmailPageModel emailPageModel)
{
super.init(listFavoritesProcessModel, emailPageModel);
products = new ArrayList<>();
final List<ProductModel> productsModel = listFavoritesProcessModel.getProducts();
productsModel.forEach(productModel -> {
final ProductData productData = getProductFacade().getProductForOptions(productModel,
Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.STOCK, ProductOption.PROMOTIONS));
products.add(productData);
});
put(EMAIL, getCustomerEmailResolutionService().getEmailForCustomer(getCustomer(listFavoritesProcessModel)));
put(DISPLAY_NAME, listFavoritesProcessModel.getCustomer().getName());
put(FROM_EMAIL, Config.getParameter("mail.smtp.user"));
put(FROM_DISPLAY_NAME, "sap");
System.out.println("DiscountNotificationEmailContext init");
}
1条答案
按热度按时间8i9zcol21#
因为
有时,Google会禁用对安全性较低或其他应用程序的访问,以保护您的帐户免受潜在漏洞的影响。可以关闭此设置,也可以为帐户
(recommended)
启用双因素身份验证。分辨率
In most cases the issue can be resolved by setting up two-step verification on Google.
通过此链接为帐户启用两步验证:Google两步验证
通过此链接生成特定密码:Google特定密码。
在下面的配置中使用生成的特定密码:mail.smtp.password=<“生成的特定密码”>
请参阅
https://support.google.com/mail/answer/7126229?visit_id=636795778044562052-2774445042&rd=2#cantsignin
本地测试电子邮件功能的另一种方法:
https://groundlevelhybris.wordpress.com/2020/03/20/email-not-getting-triggered-in-hybris-local-environment/