Reputation: 1
I am trying to send an email with sap commerce.
I have well configured the local.properties
of the config extension
mail.smtp.server=smtp.gmail.com
mail.smtp.host=smtp.gmail.com
mail.smtp.port=587
[email protected]
mail.smtp.ssl.protocols=TLSv1.2
[email protected]
mail.smtp.password=********
mail.smtp.starttls.enable=true
mail.smtp.auth=true
but after the execution of the job and when sending the email a warning is displayed
e-mail is sent to sourour siala
from email page : [email protected]
DiscountNotificationEmailContext init
INFO [TaskExecutor-master-21338-ProcessTask [8796928541622]] [GenerateEmailAction] Email message generated
INFO [TaskExecutor-master-21341-ProcessTask [8796928574390]] [DefaultEmailService] Sending Email [8796294879296] To [[[email protected]]] From [[email protected]] Subject [Exclusive Promotions on Our Products - Don't Miss Out!! ]
WARN [TaskExecutor-master-21341-ProcessTask [8796928574390]] [DefaultEmailService] Could not send e-mail pk [8796294879296] subject [Exclusive Promotions on Our Products - Don't Miss Out!! ] cause: Sending the email to the following server failed : smtp.gmail.com:587
Here are the steps of my work
I created a "ListFavoritesProcess" model extends "StoreFrontCustomerProcess" with one attribute
<attribute qualifier="products" type="ProductList">
<persistence type="property" />
<description>Attribute contains the products that will be used in the process</description>
</attribute>
then I created the process.xml file
then I created a class to start the process
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;
}
then I created the context which extends from AbstractEmailContext<ListFavoritesProcessModel>
@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");
}
Upvotes: 0
Views: 868
Reputation: 1
I had the same issue today, trying to send email messages from my Hybris / SAP Commerce Cloud platform, using a local SMTP server as relay.
Error message was : Could not send e-mail pk [1234567788999] subject [mysubject] cause: Sending the email to the following server failed : mysmtpserver.com:25
The error was caused by the special character '#' (hash sign) in the password. I had to reset the password for the mail relay account without the # character and it worked.
Hope this can help. Regards,
Upvotes: 0
Reputation: 1248
Cause
Sometimes, Google will disable access to less secure or other apps to protect your account from potential vulnerabilities. This setting can be turned off, or two factor authentication can be enabled for the account (recommended)
.
Resolution
In most cases the issue can be resolved by setting up two-step verification on Google.
Enable two-step verification for the account via this link : Google Two Steps Verification.
Generate a specific password via this link : Google Specific Passwords.
Use the generated specific password in configuration below: mail.smtp.password=<"generated specific password">
See Also
Alternate way to test email functionality locally:
Upvotes: 0