Giter Club home page Giter Club logo

mhsendmail's Introduction

MailHog Download GoDoc Build Status

Inspired by MailCatcher, easier to install.

  • Download and run MailHog
  • Configure your outgoing SMTP server
  • View your outgoing email in a web UI
  • Release it to a real mail server

Built with Go - MailHog runs without installation on multiple platforms.

Overview

MailHog is an email testing tool for developers:

  • Configure your application to use MailHog for SMTP delivery
  • View messages in the web UI, or retrieve them with the JSON API
  • Optionally release messages to real SMTP servers for delivery

Installation

Manual installation

Download the latest release for your platform. Then read the deployment guide for deployment options.

MacOS

brew update && brew install mailhog

Then, start MailHog by running mailhog in the command line.

Debian / Ubuntu Go < v1.18

sudo apt-get -y install golang-go
go get github.com/mailhog/MailHog

Go >= v1.17 (Debian Bookworm)

sudo apt-get -y install golang-go
go install github.com/mailhog/MailHog@latest

Then, start MailHog by running /path/to/MailHog in the command line.

E.g. the path to Go's bin files on Ubuntu is ~/go/bin/, so to start the MailHog run:

~/go/bin/MailHog

FreeBSD

pkg install mailhog
sysrc mailhog_enable="YES"
service mailhog start

Docker

Run it from Docker Hub or using the provided Dockerfile

Configuration

Check out how to configure MailHog, or use the default settings:

  • the SMTP server starts on port 1025
  • the HTTP server starts on port 8025
  • in-memory message storage

Features

See MailHog libraries for a list of MailHog client libraries.

  • ESMTP server implementing RFC5321
  • Support for SMTP AUTH (RFC4954) and PIPELINING (RFC2920)
  • Web interface to view messages (plain text, HTML or source)
    • Supports RFC2047 encoded headers
  • Real-time updates using EventSource
  • Release messages to real SMTP servers
  • Chaos Monkey for failure testing
  • HTTP API to list, retrieve and delete messages
    • See APIv1 and APIv2 documentation for more information
  • HTTP basic authentication for MailHog UI and API
  • Multipart MIME support
  • Download individual MIME parts
  • In-memory message storage
  • MongoDB and file based storage for message persistence
  • Lightweight and portable
  • No installation required

sendmail

mhsendmail is a sendmail replacement for MailHog.

It redirects mail to MailHog using SMTP.

You can also use MailHog sendmail ... instead of the separate mhsendmail binary.

Alternatively, you can use your native sendmail command by providing -S, for example:

/usr/sbin/sendmail -S mail:1025

For example, in PHP you could add either of these lines to php.ini:

sendmail_path = /usr/local/bin/mhsendmail
sendmail_path = /usr/sbin/sendmail -S mail:1025

Web UI

Screenshot of MailHog web interface

Contributing

MailHog is a rewritten version of MailHog, which was born out of M3MTA.

Clone this repository to $GOPATH/src/github.com/mailhog/MailHog and type make deps.

See the Building MailHog guide.

Requires Go 1.4+ to build.

Run tests using make test or goconvey.

If you make any changes, run go fmt ./... before submitting a pull request.

Licence

Copyright ยฉโ€Ž 2014 - 2017, Ian Kent (http://iankent.uk)

Released under MIT license, see LICENSE for details.

mhsendmail's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mhsendmail's Issues

Release 0.3.0?

I see there are lots of useful changes in master but not "released". Any plans for release?

Release 0.2.0 Doesn't Support -t Flag

I downloaded release 0.2.0 and it doesn't seem to support the -t flag. Looking at the source code, it seems like that might have been fixed in master, but not released. Are there any plans to do another release? If not, is master in a state where it could be downloaded and built manually? (If so, any tips on how to do so? I'm not a Go developer, just trying to set up MailHog to work with our application so we can test the emails that are generated.)

silently ignore common sendmail flags (-t and -i)

Applications by default may invoke sendmail with the -t and -i flags, behavior which mhsendmail supports out-of-box.

We've set mhsendmail as the default system mailer; e.g. in our php Dockerfiles

FROM php:5.6-alpine

...
## sendmail integration
ENV MH_SENDMAIL_SMTP_ADDR="smtp:1025"
RUN [ -e /usr/sbin/sendmail ] && mv /usr/sbin/sendmail /usr/sbin/sendmail.dist ; \
  curl -Lfo /usr/local/bin/mhsendmail \
    https://github.com/BlueAcornInc/mhsendmail/releases/download/v0.3.0-rc1/mhsendmail_linux_amd64 && \
  chmod +x /usr/local/bin/mhsendmail && \
  ln -s /usr/local/bin/mhsendmail /usr/sbin/sendmail

and can work around the issue by configuring the php sendmail path according to your documention. Instead of erroring if these flags are passed; do you think it makes sense to silently continue so we can skip the sendmail path configuration?

Many thanks

change in go.

I am not a "go" native person. ( on an off topic conversation why did they make go a snap?)

It would appear that this heavily revolves on "go get" for which I receive:

go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.

What does one do with this? Thanks in advance...

Update sendmail_path in README.md

Newer version of Go is adding the mhsendmail in ~/go/bin/mhsendmail.

The sendmail_path should be (path)/go/bin/mhsendmail

to get the (path), cd to ~/go/bin and type pwd, copy the output and append mhsendmail to it.

For example:

(myuser is an example user, you'll get different user in your end.)

  1. cd ~/go/bin, this will output: /Users/myuser/go/bin
  2. Open php.ini, find sendmail_path and change the value to /Users/myuser/go/bin/mhsendmail.

Thanks

mhsendmail does not work

I am running following command to send a mail and it does not work

mhsendmail --smtp-addr="mailhog-service:1025" [email protected] <<EOF
From: App <[email protected]>
To: Test <[email protected]>
Subject: Test message

Some content!
EOF

I am not seeing any error messages. Alternatively I was doing it with sendmail, which works:

sendmail -S mailhog-service:1025 [email protected] <<EOF
From: App <[email protected]>
To: Test <[email protected]>
Subject: Test message

Some content!
EOF

Any ideas?

New tagged release?

Any chance we could have a new tagged release please, or confirmation that the recommended way to install is to do so from source?

geerlingguy/ansible-role-mailhog#3 has been waiting on a MailHog 0.2.0 tagged release since Oct 2015, and as I'm waiting on the change in that issue, figured I 'd ask :)

arm64 builds

The current release has a linux_arm build but this does not work on Apple Silicon Macs. An arm64 build is necessary

runtime error: slice bounds out of range

Hello

Lets assume that we have this example PHP code, lets run it ;)

$ cat test_mail.php
<?php
$to = '[email protected]';
$subject = 'Test';
$message = 'Test message.';
$headers = 'From: [email protected]' . "\r\n" .
  'Reply-To: [email protected]' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();
$result = mail($to, $subject, $message, $headers);
var_dump($result);

Here is the result

$ php test_mail.php
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/mailhog/mhsendmail/cmd.Go()
        /home/vagrant/go/src/github.com/mailhog/mhsendmail/cmd/cmd.go:72 +0x10ce
main.main()
        /home/vagrant/go/src/github.com/mailhog/mhsendmail/main.go:6 +0x14

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:1696 +0x1

Here is the config

$ cat /etc/php5/cli/conf.d/zz-hitmeister.ini | grep sendmail_path
sendmail_path = /usr/bin/env /home/vagrant/go/bin/mhsendmail

Looks like it is almost the same as #3 . Hope you will have time to fix it ;)

have a nice day

Is it possible to use mhsendmail to send to a gmail server?

Hello,

This is an excellent tool, thank you. I understand that it was meant for testing but is it possible to use this so that my php webform sends mails directly to my gmail account via mhsendmail?

I saw the setting directly below in the project page and was wondering if it can accept the settings that gmail would need (shown bottom) and if so, can you give any pointers on the syntax?

./mhsendmail --smtp-addr="localhost:1026" [email protected] ...

gmail:

tls on
tls_certcheck off
auth on
host smtp.gmail.com
port 587
user [email protected]
from [email protected]
password yourgmailPassw0rd

Thanks

cannot set SMTP addr with env var

With mhsendmail installed on application container and MailHog on another, I'm unable to set smtp addr using ENV vars. mhsendmail keeps trying to use localhost:1025.

docker-compose.yml:

services:
  fpm:
    container_name: fpm
    image: php:7.2-fpm
    environment:
      - MH_SENDMAIL_SMTP_ADDR="mailhog:1025"
  mailhog:
    container_name: mailhog
    image: mailhog/mailhog
    ports:
      - "1025:1025"
      - "8025:8025"

php.ini:

sendmail_path = /usr/local/bin/mhsendmail

test call run from fpm container:

php -r "\$from = \$to = '[email protected]'; \$x = mail(\$to, 'subject'.time(), 'Hello World', 'From: '. \$from); var_dump(\$x);"

result:

error sending mail
dial tcp 127.0.0.1:1025: getsockopt: connection refused
bool(false)

running the same test from host works fine.

Client does not handle CC or BCC

I am trying to use this command line utility to send emails with some recipients cc'd and bcc'd. The client does set the headers properly but it only sends the email to the from recipient as far as I can tell. Here's an example:

mhsendmail --smtp-addr='app:9000' --from=from@localhost <<BODY
From: from@localhost
To: to@localhost
CC: cc@localhost
BCC: bcc@locahost

Example
BODY

I am only seeing one RCPT TO from tcpflow when I run this.

Mailhog Not Receiving Emails From MHSendMail

I installed mailhog & mhsendmail on a debian 10.5 virtualbox test server, running LAMP, ISPConfig, Roundcube, and Postfix.

I configured mailhog to load at boot using /etc/systemd/system/mailhog.service and I pass a ui-bind-addr variable to make the WebGUI accessible from my host machine's web browser, using the following config:

[Unit]
Description=MailHog service

[Service]
ExecStart=/usr/local/bin/mailhog \
  -api-bind-addr 127.0.0.1:8025 \
  -ui-bind-addr 192.168.0.100:8028 \ <--- This makes MH ui visible in my host machine browser (8025 has a different service already running)
  -smtp-bind-addr 127.0.0.1:1025

[Install]
WantedBy=multi-user.target

I have confirmed mhsendmail exists at /usr/local/bin/ and I have edited the default php.ini (7.3) version used by debian 10.5 /etc/php/7.3/cli/php.ini as follows:

sendmail_path = /usr/local/bin/mhsendmail

And, I have edited /etc/postfix/main.cf as follows:

relayhost = [127.0.0.1]:1025

However, none of my test emails appear in the mailhog WebGUI interface.

Anybody know what I am missing? THX

Can't easily use to replace sendmail for PHP apps

I'm trying to use mhsendmail as a sendmail replacement for some Drupal sites, and when I try sending emails using Drupal's built-in email functionality (with PHP's sendmail_path defined as /opt/mailhog/mhsendmail, where the binary is located), I get the following error in the logs:

flag provided but not defined: [email protected]
Usage of /opt/mailhog/mhsendmail:
  -from="nobody@example": SMTP sender
  -smtp-addr="localhost:1025": SMTP server address

It looks like mhsendmail expects a nice -from=address format, but Drupal (and many other PHP apps I've encountered use -faddress to provide a from email address.

Can you add support for this format, so mhsendmail can be more of a drop-in replacement for sendmail?

Installation fails on latest Go "installing executables with 'go get' in module mode is deprecated"

go version go1.17.12 linux/amd64
sh-4.4# go get github.com/mailhog/mhsendmail
go: downloading github.com/mailhog/mhsendmail v0.2.0
go: downloading github.com/ogier/pflag v0.0.1
go get: installing executables with 'go get' in module mode is deprecated.
        Use 'go install pkg@version' instead.
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

allow specifying smtpAddr &c via envars

I'd like to be able to specify defaults via envars within docker containers that use mhsendmail as default MTA. Reason is we have mailhog/smtp service running in a linked container. Possible? Awesome work.

Invalid memory address or nil pointer dereference on main.go:22

Using the latest relase (v0.1.7) I got the following error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x8048cba]

goroutine 1 [running]:
main.main()
    /Users/ikent/dev/src/github.com/mailhog/mhsendmail/main.go:22 +0xba

goroutine 2 [runnable]:
runtime.forcegchelper()
    /usr/local/Cellar/go/1.4/libexec/src/runtime/proc.go:90
runtime.goexit()
    /usr/local/Cellar/go/1.4/libexec/src/runtime/asm_386.s:2287 +0x1

goroutine 3 [runnable]:
runtime.bgsweep()
    /usr/local/Cellar/go/1.4/libexec/src/runtime/mgc0.go:82
runtime.goexit()
    /usr/local/Cellar/go/1.4/libexec/src/runtime/asm_386.s:2287 +0x1

goroutine 4 [runnable]:
runtime.runfinq()
    /usr/local/Cellar/go/1.4/libexec/src/runtime/malloc.go:712
runtime.goexit()
    /usr/local/Cellar/go/1.4/libexec/src/runtime/asm_386.s:2287 +0x1

Now, I'm not a go expert, but I think user != nil need to be used instead of user == nil on line 22 in main.go :

if err != nil && user == nil && len(user.Username) > 0 {
    username = user.Username
}

PHP mail() function triggers 'missing recipient' message

I kept digging deeper and deeper (I really want to use mhsendmail instead of sSMTP for my Drupal dev environments!), and found that PHP's mail() function is the culprit here, in terms of how it uses sendmail...

To reproduce, install PHP on a server, set the sendmail_path ini directive to the path to the mhsendmail binary, then create a script somewhere with the following test:

<?php
$to = '[email protected]';
$subject = 'Test';
$message = 'Test message.';
$headers = 'From: [email protected]' . "\r\n" .
  'Reply-To: [email protected]' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();
$result = mail($to, $subject, $message, $headers);
var_dump($result);
?>

If you run the script by accessing it through a webserver, check the webserver's error logs; you should get a message missing recipient, from mhsendmail.

The problem is that it seems mhsendmail is expecting the recipient as one of the command line args, but PHP's mail() function passes the recipient as a line in the header ('To: [recipient]'). See php-src: https://github.com/php/php-src/blob/fc33f52d8c25997dd0711de3e07d0dc260a18c11/ext/standard/mail.c#L356-L361

I think if you can make it so mhsendmail accepts the To address as the first line of stdin, it might work...

Handle multiple recipients from headers

I'm trying out this sendmail for development and found a problem with using it through PHP's mail() function. The standard way to specify recipients seems to be to put them in the message headers and if there are more than one, separate them by commas. Unfortunate thing is that the format is not as simple as #21 proposes, specified in RFC 822 and RFC 1123 and witnessed for instance by this Go EML parser unit tests (but it doesn't cover many problematic cases either).

I don't mean to add complexity to mhsendmail, but without additional parsing net/smtp.SendMail() just fails with 501 Error: Bad recipient address syntax in this case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.