DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • How To Integrate Microsoft Team With Cypress Cloud
  • Web Development Checklist
  • Top 10 Pillars of Zero Trust Networks

Trending

  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • How To Integrate Microsoft Team With Cypress Cloud
  • Web Development Checklist
  • Top 10 Pillars of Zero Trust Networks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Create an Email Newsletter Using Mule

Create an Email Newsletter Using Mule

This article shows how to create an email newsletter using Mule as shown below. Read on to find out more!

Abhay Yadav user avatar by
Abhay Yadav
·
Oct. 09, 20 · Tutorial
Like (4)
Save
Tweet
Share
10.56K Views

Join the DZone community and get the full member experience.

Join For Free

This article shows how to create an email newsletter using Mule as shown below.

newsAPIHere, I have used NewsAPI, you can use any API of your choosing. Almost all APIs need clients to authenticate themselves before serving the request. So, the first step is to register for a dev account on the portal and get an API key.

Creating a Mule Application

  • Create a new Mule project. Configure a scheduler source that will trigger the application every day at 8 AM.scheduler
  • Configure an HTTP requester to call the API and fetch news metadata. You can head to the documentation of the API being used and get the hostname, base URL, etc.http request

error list

The API Key is passed in header X-API-Key. Also have passed the query parameter to fetch news only for India.

XML
 




xxxxxxxxxx
1
15


 
1
<http:headers>
2

          
3
      <![CDATA[#[
4

          
5
output application/java --- { "X-Api-Key" : "${apiKey}" }]]]>
6

          
7
</http:headers> 
8

          
9
<http:query-params >
10

          
11
      <![CDATA[#[
12

          
13
output application/java --- { country: "in" }]]]>
14

          
15
</http:query-params>



  • Once the metadata is fetched, we will format it using Dataweave.
JSON
 




xxxxxxxxxx
1
25


 
1
%dw 2.0 
2

          
3
output application/xml writeDeclaration = false 
4

          
5
--- 
6

          
7
section: { 
8

          
9
     h2: "Here's your news feed generated by Mule", 
10

          
11
     (payload.articles filter ($.publishedAt > (now() - |P1D|) as String {format: "yyyy-MM-dd'T'hh:mm:ss"}) map (article, articleIndex) -> {
12

          
13
           div @(style: " border: 1px solid #000; padding: 5px 10px;margin: 10px;height:100px;"): {
14

          
15
               (img @(src: article.urlToImage, style: "height:100px; width: 100px;margin-right: 5px;float: left;"): "") if(article.urlToImage != null),
16

          
17
                a @(href: article.url, style: "text-decoration: none;color: #002133;"): 
18

          
19
                h2: article.title, (p: article.description) if (article.description != null) 
20

          
21
           }
22

          
23
      }) 
24

          
25
}



Since the API doesn't support fetching records published in a certain time period, I have filtered the payload to include only articles published in the last 24 hours. Also, have applied some basic styling to make the content readable.

Configure an SMTP Send operation to send mail. Create a global Email configurationemail Open the Advanced tab, select Edit inline in the drop-down and add mail.smtp.starttls.enable property with true value.

no addresses

Note: If using Gmail, don't forget to turn on Less Secure Apps. Also, change Content-type to text/HTML to send HTML enriched content

That's it. Deploy the application and it will send a mail every day at 8 AM to the configured email with news articles from the last 24 hours.

To test the application locally, the scheduler can be replaced with an HTTP listener.

application API News Database Mail (Apple) Metadata Fetch (FTP client) job scheduling app Testing

Published at DZone with permission of Abhay Yadav. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • How To Integrate Microsoft Team With Cypress Cloud
  • Web Development Checklist
  • Top 10 Pillars of Zero Trust Networks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: