SmartHost (MailGun) - Specify AUTH for some domains and the rest default.

cyben76

Member
Jul 5, 2019
5
0
1
singapore
cPanel Access Level
Root Administrator
Hi,

I'm using MailGun as a SmartHost with the following:

#Section: AUTH
Code:
mailgun_login:
driver = plaintext
public_name = LOGIN
hide client_send = : ${extract{user}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}}}}: ${extract{pass}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}}}}
#Section: ROUTERSTART
Code:
mailgun:
driver = manualroute
domains = ! +local_domains
transport = mailgun_transport
route_list = "* smtp.mailgun.org::587 byname"
host_find_failed = defer
no_more
#Section: TRANSPORTSTART
Code:
mailgun_transport:
driver = smtp
hosts = smtp.mailgun.org
hosts_require_auth = smtp.mailgun.org
hosts_require_tls = smtp.mailgun.org
#My /etc/exim_smarhosts
Code:
domain1.com: domain=domain1.com user=MAILGUN_smtp_user1 pass=MAILGUN_api_password1
domain2.com: domain=domain2.com user=MAILGUN_smtp_user2 pass=MAILGUN_api_password2
So the above is only for 2-3 domains that are in my /etc/exim_smarhosts how do I route all other domains on the server to another MailGun credential without manually adding the domains to /etc/exim_smarhosts , for example:

Code:
mailgun_login:
driver = plaintext
public_name = LOGIN
hide client_send = : Default-SMTP-Login:Default-Password
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,027
313
cPanel Access Level
Root Administrator
Hey there! I'm not sure there is going to be a way to do that without some manual intervention. While this is a bit outside the scope of cPanel, this post gets referenced a lot for this type of work, and is still valid today:


If you need more than that, it might be best to reach out to the Exim user group directly, or submit a feature request to our team to see if we can make this process more automated in the future.
 

cyben76

Member
Jul 5, 2019
5
0
1
singapore
cPanel Access Level
Root Administrator
Hey there! I'm not sure there is going to be a way to do that without some manual intervention. While this is a bit outside the scope of cPanel, this post gets referenced a lot for this type of work, and is still valid today:


If you need more than that, it might be best to reach out to the Exim user group directly, or submit a feature request to our team to see if we can make this process more automated in the future.
Hey cPRex,

Thank you for the quick reply, I've already visited that post you mentioned, and several others, before starting this thread, but that thread does not show how to change the AUTH to default. I've joined the Exim User group but my email post keep bouncing back, so I have no idea how to post a question to them.
 
Last edited:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,519
1,027
313
cPanel Access Level
Root Administrator
How ironic that you're getting bouncebacks from the Exim list...

I couldn't find anything else on my end about this type of split delivery when I searched either, but it's always possible another user has configured this and will join in with their thoughts.
 

cyben76

Member
Jul 5, 2019
5
0
1
singapore
cPanel Access Level
Root Administrator
After going thru the Exim Documentation, this is what I came up with:
Code:
mailgun_login:
 driver = plaintext
 public_name = LOGIN
 hide client_send = : ${if eq{${lookup{$sender_address_domain}partial-lsearch{/etc/exim_smarthosts}{$value}}}{}{DEFAULT_MAILGUN_SMTP_LOGIN : DEFAULT_MAILGUN_SMTP_PASS}{${extract{user}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}{$value}fail}}} : ${extract{pass}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}{$value}fail}}}}}
It works in Exim cli, but when I try sending an email I get an error. Most likely some syntax issues with regards to the colon : , still can't figure it out. The : is recognized as the start of a new string so it expects a } to close the string. Adding double colon:: will result in Auth failure.
 

cyben76

Member
Jul 5, 2019
5
0
1
singapore
cPanel Access Level
Root Administrator
Ok finally found out why I could not post to the Exim-users mailing list, I think it was because I used my work email. I registered with my Gmail account and was able to post a question.

I'll post here so if anyone is looking for the same answer could find it.

So this is what Jasen Betts from Exim-user:
First Option:
Code:
change lsearch to nwildlsearch
add a * entry at the end of the /etc/exim_smarthosts file. that entry has the default credentials
Second Option:
Code:
use the not-found branch of "lsearch" or "extract" to get the default credentials.


    which means code like:


     hide client_send = : \
      ${extract{user}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}{$value}{DEFAULTUSER}}}}:\
      ${extract{pass}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}{$value}{DEFAULRPASS}}}}


    or


     hide client_send = : \
      ${extract{user}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}}}{$value}{DEFAULTUSER}}:\
      ${extract{pass}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}}}{$value}{DEFAULRPASS}}
I went with the second option and it works perfectly!

So my Exim config be like:

#Section: AUTH
Code:
mailgun_login:
 driver = plaintext
 public_name = LOGIN
 hide client_send = : \
${extract{user}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}}}{$value}{DEFAULTUSER}}:\
${extract{pass}{${lookup{$sender_address_domain}lsearch{/etc/exim_smarthosts}}}{$value}{DEFAULRPASS}}
#Section: ROUTERSTART
Code:
mailgun:
driver = manualroute
domains = ! +local_domains
transport = mailgun_transport
route_list = "* smtp.mailgun.org::587 byname"
host_find_failed = defer
no_more
#Section: TRANSPORTSTART
Code:
mailgun_transport:
driver = smtp
hosts = smtp.mailgun.org
hosts_require_auth = smtp.mailgun.org
hosts_require_tls = smtp.mailgun.org
# /etc/exim_smarhosts
Code:
domain1.com: domain=domain1.com user=MAILGUN_smtp_user1 pass=MAILGUN_api_password1
domain2.com: domain=domain2.com user=MAILGUN_smtp_user2 pass=MAILGUN_api_password2