Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Connect to my server via SMTP and send emails

  1. #1
    Join Date
    Sep 2020
    Beans
    6

    Smile Connect to my server via SMTP and send emails

    I have Ubuntu 18.04 server. I have installed Postfix. I have set SPF record for domain + DKIM + TLS. Everything is working. Basically I can send emails via PHP scripts.

    Now I want to send emails from this server by connecting to it via SMTP from remote server. How do I do that? I think I have to install Dovecot? Or can I use relay? I need simple solution. Simple authentication and send that email. That would be it.

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Connect to my server via SMTP and send emails

    Dovecot is for imap only and has nothing to do with SMTP. Postfix is an MTA and all you need for a basic SMTP server. It can be a relay or not. Depends on your requirements. Generally, it is a bad idea to setup postfix as a relay, since when it is an open-relay, the world will discover it quickly and start using it to spam everyone.

    SMTP traffic is 2 types. Unauthenticated and authenticated.

    Unauthenticated is email between unrelated SMTP servers. All this happens on post 25/tcp. That's what happens when smtp.gmail.com sends you an email at bob@domain.com. Your email server with a DNS MX record for domain.com accepts random emails from any SMTP in the world looks at the TO, decides if those make sense for the mail.domain.com server to accept or not. If the "TO" isn't for a domain that postfix has been configured to accept, then the email should be rejected. If the remote server connecting to you mail.domain.com server is in a spam block list or the domain it comes from isn't in the SPF list or the DKIM signatures for the message and the server don't match, then it should also be rejected. SMTPS is optional. Get SMTP working first.

    Authenticated is email between a client that connects to your server with a login on port 587/tcp or 465/tcp. That means the email server must have a list of all users and all aliases, in addition to a password database. Running an email server that does this requires stronger security, because 100,000 "bad guy" servers around the world will start trying to brute force userids and passwords very quickly. Be certain you setup a limit for the number of failed passwords for each userid and from each remote server. Back when I allowed remote email to be sent without a VPN connection first, my server was seeing hundreds of thousands of attempted logins. In the end, it was just easier to take authenticated email connections off the internet and mandate client access go through a VPN, get onto a subnet we control before allowing any SMTP from end-users.

    If you want steps, howtoforge has this: https://www.howtoforge.com/ispconfig...debian-ubuntu/ Just don't enable the parts you don't want and don't open the firewall ports for services you don't want exposed.
    Now I want to send emails from this server by connecting to it via SMTP from remote server. How do I do that? I think I have to install Dovecot? Or can I use relay? I need simple solution. Simple authentication and send that email. That would be it.
    Any remote email server should be able to send unauthenticated SMTP to your server, unless the system is blocking port 25 or the ISP is blocking port 25. This assumes you own the domain and have configured the C, A, and MX records in DNS for the mail server.
    If you want a remote server that is under your control to be allowed to send SMTP to this server, then configure the remote server to post to it as a relay host in the postfix. This happens on the remote system. /etc/postfix/main.cf - obviously, use your IP or DNS name.
    Code:
    relayhost = 150.22.22.45
    On the local email server, setup the mynetworks in the /etc/postfix/main.cf to include that remote system. There are other details, mostly around the FQDNs for each system that should be related, but those aren't THAT important, just handy for good filters.

    Be certain you run SMTP tests from remove services to verify that none of your email system will accept emails from any servers and relay them to servers you don't control, unless the domain used comes from systems under your control. If you fail to do this for very long, your systems will be placed onto a email server blacklist. Good luck getting off that.

  3. #3
    Join Date
    Sep 2020
    Beans
    6

    Re: Connect to my server via SMTP and send emails

    Thank you for your reply. I had to read it 3 times to absorb all the information.

    I'm not sure your linked step by step guide is related. My end goal is to give you (or somebody else) this information:

    PHP Code:
    MAIL_MAILER=smtpMAIL_HOST=mail.myserver.comMAIL_PORT=2525MAIL_USERNAME=theFuMAIL_PASSWORD=yourPasswdMAIL_ENCRYPTION=tls 
    You will insert it to into you PHP framework and will be able to use my server to send emails. That's the goal.

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Connect to my server via SMTP and send emails

    If you want to treat remote php programs as "users", then it isn't an SMTP -to- SMTP connection. It is an end-user -to- email server connection. This doesn't sound like a very good idea to me. You are at the whim of these other systems and are trusting them not to spam the world. If any one of them does, then you'll need to cancel their account quickly and probably try to get your email server removed from blacklist status. You couldn't pay me enough to do that. $20K/month isn't enough, since I'd need a team of people to deal just with those negative aspects.

    If it were me, I'd rather have those remote servers setup their own email sending stuff and keep me and my systems out of it. When they get blacklisted, it wouldn't impact my server at all.

    Plus, php webapps are constantly being cracked, so having email sending easily available from them wouldn't be good.

    The link for instructions above most definitely sets up an email server that can accept inbound end-user emails. The usernames/passwords are stored inside a MariaDB, I think. Having 20,000 email users wouldn't be hard for that single system on any $5K Linux server. 200 email users would be easy on a $10/month VPS following those instructions.

    BTW, while you could use port 2525/tcp for this, normally port 587/tcp would be preferred.

  5. #5
    Join Date
    May 2010
    Beans
    1,712

    Re: Connect to my server via SMTP and send emails

    Can you send an email using telnet OK? Does this work as expected?

  6. #6
    Join Date
    Sep 2020
    Beans
    6

    Re: Connect to my server via SMTP and send emails

    Essays on internet security won't help me at all.

    I simply have server that is capable of sending emails. It works. On separate machine I want fill in these fields in Laravel (PHP framework) and use first server to send emails.

    PHP Code:
    MAIL_MAILER=smtp
    MAIL_HOST
    =mail.myserver.com
    MAIL_PORT
    =2525
    MAIL_USERNAME
    =theFu
    MAIL_PASSWORD
    =yourPasswd
    MAIL_ENCRYPTION
    =tls 
    Every single emailing service will give you access to their server in this format. So it is possible and secure. I just don't know how to set it up on my own server.

  7. #7
    Join Date
    Oct 2006
    Beans
    57,606

    Re: Connect to my server via SMTP and send emails

    Thread moved to the "Server Platforms" forum.

  8. #8
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Connect to my server via SMTP and send emails

    http://www.postfix.org/SASL_README.html and https://www.howtoforge.com/postfix-s...cure-port-only are probably what you want.

    How many spam emails did you get today? Guess where those originated? Not from my systems.

  9. #9
    Join Date
    Sep 2020
    Beans
    6

    Re: Connect to my server via SMTP and send emails

    How would they originated from my server if login is necessary?

  10. #10
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,554
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Connect to my server via SMTP and send emails

    Are you only wanting capability to send email from scripts on your server? You can just use a lightweight SMTP mailer configured to use an existing mail server.

    Example: Setup Server for Sending Email using sSMTP

    LHammonds

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •