Open jlellis opened 5 years ago
@jlellis
due to the reference your config is a little ambiguous and the configuration format itself is a little redundant.
try this:
{
"mhog-cmi-001.pavlovmedia.corp": {
"name": "mhog-cmi-001.pavlovmedia.corp",
"host": "mhog-cmi-001.pavlovmedia.corp",
"port": "25",
"mechanism": "NONE"
}
}
or just change the json object key and name
property to the same value.
That fixed it for me. Thank you @ns3777k
Could you explain how you set the environment variable? I put this in my ~/.profile
file:
export MH_OUTGOING_SMTP="$HOME/.mailhog/outgoing-smtp.json"
but mailhog is not picking up this value (the dropdown list is empty)
My second try was adding the path in the file /etc/systemd/system/mailhog.service
:
ExecStart=/usr/bin/env /usr/local/bin/mailhog -outgoing-smtp="/home/user/.mailhog/outgoing-smtp.json" > /dev/null 2>&1 &
and running the following commands:
systemctl daemon-reload
systemctl enable mailhog
but it's still not working.
It only works when I run mailhog manually with the file path attached like so:
mailhog -outgoing-smtp="/home/user/.mailhog/outgoing-smtp.json"
I'm totally confused...
@simonschaufi Well, I assume you're using linux. First off, let's make sure the basic example works correct:
$ MH_OUTGOING_SMTP="/home/user/.mailhog/outgoing-smtp.json" mailhog
mailhog should pick this up.
@ns3777k yes, that works
@simonschaufi good. what's the final goal? you wanna start it as a systemd service?
Exactly. Do I need to place the environment in .bashrc or is .profile correct? I'm using Ubuntu 18.
When i execute this command: echo $MH_OUTGOING_SMTP
I get: /home/user/.mailhog/outgoing-smtp.json
so the environment variable is available in Terminal
@simonschaufi Should be working fine specifying the systemd service without env variables.
Service /etc/systemd/system/mailhog.service
:
[Unit]
Description=MailHog Service
[Service]
Type=simple
ExecStart=/usr/bin/env /tmp/MailHog_linux_amd64 -outgoing-smtp=/tmp/servers.json > /dev/null 2>&1 &
[Install]
WantedBy=multi-user.target
Then:
$ sudo systemctl daemon-reload
$ sudo systemctl start mailhog
$ sudo systemctl status mailhog
● mailhog.service - MailHog Service
Loaded: loaded (/etc/systemd/system/mailhog.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-02-18 00:24:24 MSK; 4s ago
Main PID: 16823 (MailHog_linux_a)
Tasks: 6 (limit: 4915)
Memory: 2.1M
CGroup: /system.slice/mailhog.service
└─16823 /tmp/MailHog_linux_amd64 -outgoing-smtp=/tmp/servers.json > /dev/null 2>&1 &
With /tmp/servers.json
:
{
"mhog-cmi-001.pavlovmedia.corp": {
"name": "mhog-cmi-001.pavlovmedia.corp",
"host": "mhog-cmi-001.pavlovmedia.corp",
"port": "25",
"mechanism": "NONE"
}
}
@ns3777k can you verify that it works on your machine also with the environment variable? I don't want to touch "internal" files to have a clean system that I can easily setup again.
@simonschaufi yes, it does. if you wanna use env variables with systemd, you should put the env inside the service definition:
[Unit]
Description=MailHog Service
[Service]
Environment="MH_OUTGOING_SMTP=/tmp/servers.json"
Type=simple
ExecStart=/usr/bin/env /tmp/MailHog_linux_amd64 > /dev/null 2>&1 &
[Install]
WantedBy=multi-user.target
then daemon reload and restart
So the daemon doesn't have access to the variables I declared in my ~/.profile
?
Well, I would not recommend setting systemd service and pointing it to a file inside a user home directory. Technically it's possible with setting EnvironmentFile
in the service definition (https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=).
Instead I'd recommend setting the environment variables in a separate file outside the home directory or specifying arguments in ExecStart
.
For the original issue here - perhaps the documentation needs a little clue for this? A line below the example JSON would be useful, viz:
Ensure the name
parameter and the key for the entire server block match exactly (both shown as server name
in the above example.)
Some other things to note which may be useful for people who get stuck:
The email
field is ambiguous. Is it the From Email
or the To Email
. It seems to be neither.
In the password
field - if you are using with an SMTP API such as Sengrid - the password (aka API secret) provided by Sendgrid may contain backslashes. This will create a valid JSON file, however, this won't work with Mailhog. Regenerate the API key/secret on Sendgrid until a secret without backslashes in it is obtained.
I'm trying to provide my developers with a pre-defined 'Release' smtp target by providing MailHog with a -outgoing-smtp JSON file. I've fiddled with this for several hours. I can see the entry appearing in the Release selection box in the web gui, but using it always fails.
When running MailHog from the command line in the foreground (or with a systemd service defintion that routes stdout to the syslog) I always get log output like this:
So it seems to be correctly saving the NAME of the outbound server, but not the host/port content, it just fails.
If I manually create a Custom setting in the web gui with the same values, it works, and logs thusly:
I've passed the json file through jq as a syntax check and it worked fine.
The current content of that file is:
I've spent several hours trying various things in this file and I've reached my limit of patience with it. I have googled multiple times looking for anyone posting a working example of this file with no luck at all.
I just want to have the Release page provide a known-working default config for the developers to use. From what I can tell, the go code is simply ignoring the Host and Port items in this file no matter how I provide it.