Allowing hmailserver to relay emails from another domain

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
glennlittleford
New user
New user
Posts: 8
Joined: 2018-08-12 09:00

Allowing hmailserver to relay emails from another domain

Post by glennlittleford » 2018-08-12 09:26

Hi everyone.

I have hmailserver 5.6.6 installed on a Win 2012R2 server. Its serving email for a domain hosted on the same server, lets call it mydomain.com.

I have a intranet application written in PHP that needs to send emails. I have created a email account php@mydomain.com. The PHP code, be it installed on the local server or another server on the internet, can connect and send emails using this account where the sender/return address is php@mydomain.com

What I need to do is send email using php@mydomain.com credentials, but with a sender address from another domain. For example, I've installed my php intranet on a businesses server, they need the intranet to send emails where the sender/return address is a employees ( for example, Fred@thebusiness.com ) email address. In testing, hmailserver understandably rejected this.

Is there a way to tell hmailserver to process emails with a email address someone@thebusiness.com in the sender/return address when the connected user was logged in with php@mydomain.com? I know what the new business domains are, so I can create a list, but is there a way to implement this.

I did try adding the business domain and accounts to the hmailserver, this would work, but if the intranet was sending a email to another employee on the same business domain, the email would never leave the mydomain.com server as it thinks its already home.

Thanks
Glenn

palinka
Senior user
Senior user
Posts: 1923
Joined: 2017-09-12 17:57

Re: Allowing hmailserver to relay emails from another domain

Post by palinka » 2018-08-12 12:56

You want to send from anyone@external domain to anyone@external domain? That can only be done by creating an open relay. If you're sure the other php sending machine will not be sending anything other than your script messages, you can create a new IP range solely for that machine and allow external to external without authentication. Or install HMS on the other machine and do the same thing but only for the My Computer IP range.

Or if I misunderstood and the messages are only being sent to a particular domain, you can create a route so they'll be sent externally instead of trying to deliver locally.

glennlittleford
New user
New user
Posts: 8
Joined: 2018-08-12 09:00

Re: Allowing hmailserver to relay emails from another domain

Post by glennlittleford » 2018-08-12 14:22

Yes, the someone@thebusiness.com could be sending to anyone@anywhere.com. The IP of the server running the php may not be fixed, but the domain of the From address will be fixed, it will always be someone@thebusiness.com. Is there a way to to accept relaying of messages based on a senders domain instead of the IP of the sending PC? They will always be connecting to the mail server with a known user ( php@mydomain.com ) and password, so there is a degree of authentication.

This intranet software is been installed on servers for several different businesses, all different domains. I know what the their email addresses are, but the sender IP's may not be fixed. Installing HMS on the servers isnt a option unfortunately. I have tried using their own email servers, but this is proving difficult, am looking for a generic option I can apply to all businesses.

I may be using the wrong terminology, email isn't my area sorry.

Glenn

palinka
Senior user
Senior user
Posts: 1923
Joined: 2017-09-12 17:57

Re: Allowing hmailserver to relay emails from another domain

Post by palinka » 2018-08-12 17:16

Settings > protocols > smtp > routes

I'm not any expert on routes, but a little trial and error will work things out for you. I'm sure someone will jump in if I'm wrong about this, but I would set up thebusiness.com domain and the php email user for authentication purposes. Then treat senders as local and recipients as remote. I think in that way - for messages bound to real thebusiness.com recipients - it will always attempt to deliver to the actual thebusiness.com mx instead of locally.

User avatar
mattg
Moderator
Moderator
Posts: 20794
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Allowing hmailserver to relay emails from another domain

Post by mattg » 2018-08-12 23:36

palinka wrote:
2018-08-12 12:56
You want to send from anyone@external domain to anyone@external domain? That can only be done by creating an open relay.
That's incorrrect
glennlittleford wrote:
2018-08-12 09:26
What I need to do is send email using php@mydomain.com credentials, but with a sender address from another domain. For example, I've installed my php intranet on a businesses server, they need the intranet to send emails where the sender/return address is a employees ( for example, Fred@thebusiness.com ) email address. In testing, hmailserver understandably rejected this.
The way to achieve this is to allow external to external WITH SMTP AUTH in your IP range that matches your webserver.

hMailserver allows you to AUTH with one account and then to send FROM another account out of the box, and will do this for localhost under default configuration of IP ranges.

If you don't want that to happen you need to script around it, and modify your IP ranges
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
mattg
Moderator
Moderator
Posts: 20794
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Allowing hmailserver to relay emails from another domain

Post by mattg » 2018-08-12 23:38

glennlittleford wrote:
2018-08-12 14:22
The IP of the server running the php may not be fixed, but the domain of the From address will be fixed, it will always be someone@thebusiness.com
This is unusual.

Why will PHP be rolled out to random servers and have the FROM address hardcoded...that doesn't make sense.

However if you really need to do this, this can be achieved with some scripting in hMailserver. How is your VBS?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

palinka
Senior user
Senior user
Posts: 1923
Joined: 2017-09-12 17:57

Re: Allowing hmailserver to relay emails from another domain

Post by palinka » 2018-08-13 00:52

mattg wrote:
2018-08-12 23:36
The way to achieve this is to allow external to external WITH SMTP AUTH in your IP range that matches your webserver.

hMailserver allows you to AUTH with one account and then to send FROM another account out of the box, and will do this for localhost under default configuration of IP ranges.
Of course! I think he's stuck on the sender email address, as i was, with the domain in use by another mx. Create a random domain/user solely for the purpose of authentication. Routes & "thebusiness.com" domain not necessary.

glennlittleford
New user
New user
Posts: 8
Joined: 2018-08-12 09:00

Re: Allowing hmailserver to relay emails from another domain

Post by glennlittleford » 2018-08-13 02:39

mattg wrote:
2018-08-12 23:38
glennlittleford wrote:
2018-08-12 14:22
The IP of the server running the php may not be fixed, but the domain of the From address will be fixed, it will always be someone@thebusiness.com
This is unusual.

Why will PHP be rolled out to random servers and have the FROM address hardcoded...that doesn't make sense.

However if you really need to do this, this can be achieved with some scripting in hMailserver. How is your VBS?
Each business has its own email domain, eg thebusinessA.com and thebusinessB.com. And their email server is usually in the cloud somewhere. But the server where the PHP is running is a local file server at their business, and in a couple of cases is on a unfixed WAN IP address. So I would like to tell the my hmailserver to accept relays for someone@thebusinessA.com, or someone@thebusinessB.com, without using a sending IP address rule. I will know the thebusinessA.com, theBusinessB.com etc addresses, and I can tell PHP to log in with its own username and password, so was hoping thats enough to configure and allow relaying.

User avatar
mattg
Moderator
Moderator
Posts: 20794
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Allowing hmailserver to relay emails from another domain

Post by mattg » 2018-08-13 03:12

Your solution then is to allow external to external WITH SMTP AUTH on the internet IP range in hMailserver

This isn't ideal and allows anyone who authenticates with your server to send mail to and from any one
You could lock this down with some Scripts, by modifying your eventhandlers.vbs and enabling scripts on your hmailserver.



Wouldn't it be easier to set each of the php scripts to point to their own (hosted or otherwise) mail servers ? It would certainly be more secure.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

glennlittleford
New user
New user
Posts: 8
Joined: 2018-08-12 09:00

Re: Allowing hmailserver to relay emails from another domain

Post by glennlittleford » 2018-08-13 07:52

mattg wrote:
2018-08-13 03:12

Wouldn't it be easier to set each of the php scripts to point to their own (hosted or otherwise) mail servers ? It would certainly be more secure.
Yes thats true. In the past the PHP software just needed to send simple email messages ( ie, Delivery arrived, job overdue, etc. ) to the business employees, and the from address was on my own domain. Now it needs to send emails with a PDF attachment on behalf of the employees, to other people. I tried asking them to create a new email on their own email domain for my PHP to use, but this is harder than it should be. One email server is so slow the script sometimes times out, another has a IT provider who refuses to add it because "PHP is used by hackers", etc, etc. So I thought if I can get my own email server to do the job, it would be easier for me.

Thanks, I'll see if I can do the "allow external to external WITH SMTP AUTH on the internet IP range in hMailserver" thing, I'm inexperienced with the hmailserver but need to learn.

Regards
Glenn

tunis
Normal user
Normal user
Posts: 246
Joined: 2015-01-05 20:22
Location: Sweden

Re: Allowing hmailserver to relay emails from another domain

Post by tunis » 2018-08-13 14:58

Don't forget that companyA and companyB most add your mail server in there SPF record if they have any.
HMS 5.6.8 B2494.25 on Windows Server 2019 Core VM.
HMS 5.6.8 B2494.24 on Windows Server 2016 Core VM.
HMS 5.6.7 B2425.16 on Windows Server 2012 R2 Core VM.

Post Reply