Skip to Content
Menú
This question has been flagged

Hi,


Is it possible to send an email to new newsletter subscribers with a unique, single-use coupon?

We are using version 15 at the moment, but we are opgrading soon. 

Avatar
Descartar
Best Answer

I have the same challenge. But no answers yet. I can imagine that every busniess case exactly needs this basic feature and there must be a simple solution. Maybe somehow with marketing automation? At the moment I have no answer at all... Any hints from anybody?

Avatar
Descartar
Autor

Hi Philipp,

I found a solution to the challenge using an automation rule and some custom code. Here’s how I’ve set it up in v17:

Model: Mailing List Subscription (mailing.subscription)

Trigger: On save

Trigger fields: Created on

Apply on: [["list_id","ilike","Newsletter"]]
(Replace 'Newsletter' with the name of your target mailing list.)

Action to do: Execute Code

Here’s the code I use:

COUPON_PROGRAM_ID = 4 # example: 10% off your next order
MAIL_TEMPLATE_ID = 8 # typically the template '[Sales] Coupon: Send by Email' or a copy of it
COUPON_MODEL = None

# version check
if 'coupon.coupon' in env: # we are in v15
COUPON_MODEL = 'coupon.coupon'
elif 'loyalty.card' in env: # we are in v17
COUPON_MODEL = 'loyalty.card'

# sanity check, if coupons cannot be found don't crash
if COUPON_MODEL:
subscriber_email = record['contact_id']['email']

# 2. Generate coupon
coupon = env[COUPON_MODEL].sudo().create({
'program_id': COUPON_PROGRAM_ID,
})

# 3. Send coupon by email
template = env['mail.template'].sudo().browse(MAIL_TEMPLATE_ID)
template.send_mail(coupon.id, force_send=True, email_values={'email_to': subscriber_email})
if COUPON_MODEL == 'coupon.coupon': # mark coupon as sent (v15 only)
coupon.write({'state': 'sent'})
else: # add 1 credit to coupon (v17 only)
coupon.write({'points': 1.0})

This setup ensures that a coupon is automatically generated and sent by email whenever a subscription to a specific mailing list (e.g., "Newsletter") is created.

Related Posts Respostes Vistes Activitat
0
d’oct. 24
1137
0
de maig 24
1639
0
d’abr. 24
1274
2
de febr. 24
3325
0
de des. 23
1446