# Email Relay Outgoing

I used Centos 6.8 to configure a Mail Relay.

1st step -

Install exim in your server :

```
yum install exim-mysql -y
```

Usually centos default MTA is postfix, so we need to change the default MTA to exim, with command below :

```
alternatives --config mta
```

It will bring you below selection :

```
There are 2 programs which provide 'mta'.

Selection Command
-----------------------------------------------
* 1 /usr/sbin/sendmail.postfix
+ 2 /usr/sbin/sendmail.exim

Enter to keep the current selection[+], or type selection number:
```

Choose 2 to use exim as the default MTA, (I have chosen 2 in my example).

```
service postfix stop
chkconfig postfix off
service exim start
chkconfig exim on
```

Now we need to change the exim configuration at /etc/exim/exim.conf

Change to below :

```
primary_hostname = acaprelay.amirulasyraf.com <- my mail relay hostname
hostlist relay_from_hosts = 127.0.0.3 : (add your mail server IP here) <- to make sure that you are allowed to relay in this server
```

Then find a section called "router" in the configuration and make sure the router is set as below :

```
dnslookup:
 driver = dnslookup
 domains = ! +local_domains
 transport = remote_smtp
 ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8
 no_more
```

Above config will tell route all email, and send it for you to the recipient.

But we must make sure that your mail server know where to relay the  server to, so you need to login to your mail server (origin server).

Then edit the exim config for smarthost as below :

```
smarthost:
 driver = manualroute
 domains = ! +local_domains
 transport = remote_smtp
 route_list = * acaprelay.amirulasyraf.com    <- this will guide my mail server to relay email to my new Mail Relay Server
 no_more
 no_verify
```

After completed all above steps, try to send using your origin server to anyone.You will got the header of the email as below :

```
Return-Path: aberu@amirulasyraf.com
Received: from *.*.*.*(LHLO ips1-mail.ipserverone.com) (*.*.*.*) by
 ips1-mail.ipserverone.com with LMTP; Fri, 6 Jan 2017 10:55:17 +0800 (MYT)
Received: from barracuda.ipserverone.com (mail.as2.ipserverone.com [*.*.*.*])
	by ips1-mail.ipserverone.com (Postfix) with ESMTP id 7EFE4516966A
	for <asyraf@ipserverone.com>; Fri,  6 Jan 2017 10:55:17 +0800 (MYT)
X-ASG-Debug-ID: 1483671316-068b3e1093354110001-4XlEqv
Received: from acaprelay.amirulasyraf.com ([*.*.*.*]) by barracuda.ipserverone.com with ESMTP id OFtS3gY6HqFmSdZT for <asyraf@ipserverone.com>; Fri, 06 Jan 2017 10:55:16 +0800 (MYT)
X-Barracuda-Envelope-From: aberu@amirulasyraf.com
X-Barracuda-Apparent-Source-IP: *.*.*.*
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=amirulasyraf.com; s=mail;
	h=Message-ID:From:Date:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:To; bh=1bP+QR4oOJI80qfwgQhGi2RMJffC7P++shP6eV7AOkU=;
	b=A01VatqmaxW7vdK620CspLLO/c3D9QzeFoO8+1YZT2JlUxPXNzRNfT44p7i6Rzf+z8DUckDiyAun1mOjGJxGcm8Q9WryiJB4RQ/SIVdl2pOcZ1zNQ+OzPH9YMfFBklSZ4PbELCi+6TjF110YPu99sz7x0053AJyS8tFPLjwUH3A=;
To: asyraf@ipserverone.com
Subject: Test
```

As you can see above, it stated that it received from my Mail Relay ([acaprelay.amirulasyraf.com](http://acaprelay.amirulasyraf.com/)).<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kb.asyraf.my/application-guide/email-relay-outgoing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
