Announcement

Collapse
No announcement yet.

How do servers send and receive email?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do servers send and receive email?

    I'm trying to get my head around what happens when you send & receive emails from an email server at home.

    I think some of my confusion is around port numbers, and what happens if you change the defaults.

    Say someone wants to send an email to foo@yourdomain.com - as I understand it, their email client will look up an MX record for yourdomain.com from your DNS, which will tell them the right IP address to send the email to. They then make a connection... but on which port? If you change the port in your server's settings, how do the emails get through?

    I believe people with ISPs that block port 25 can still receive mail by changing port nos, is this because the email is sent to the ISP's server and then transferred the last little bit over a different port, allowing ISPs to monitor all email on their system?

    Similar story for outgoing mail - if you use a non-standard port to send, do you need to route the mail through another server like your ISP's mail server that will send it on from there on the standard port?

    Feathers
    samhobbs.co.uk

    #2
    An explanation: http://en.wikipedia.org/wiki/Email#Operation_overview
    Windows no longer obstructs my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      Thanks, I've read that before, but the example given on Wikipedia isn't exactly the same as my usage case.

      I'm asking what happens if I use my own email server, a step that isn't included in the Wiki example. Does my server connect to "smtp.a.org" (or similar) as the first link in a chain, or does it replace it?

      If it replaces it, is this why it's a problem when ISPs block port 25, because then your server is unable to do step 4? If the message was sent using SMTP on a different port, would it get delivered or not? Does it depend on whether the server at the other end is listening for incoming mail on that port?

      Feathers
      samhobbs.co.uk

      Comment


        #4
        Originally posted by Feathers McGraw View Post
        I'm trying to get my head around what happens when you send & receive emails from an email server at home.

        I think some of my confusion is around port numbers, and what happens if you change the defaults.

        Say someone wants to send an email to foo@yourdomain.com - as I understand it, their email client will look up an MX record for yourdomain.com from your DNS, which will tell them the right IP address to send the email to. They then make a connection... but on which port? If you change the port in your server's settings, how do the emails get through?

        I believe people with ISPs that block port 25 can still receive mail by changing port nos, is this because the email is sent to the ISP's server and then transferred the last little bit over a different port, allowing ISPs to monitor all email on their system?

        Similar story for outgoing mail - if you use a non-standard port to send, do you need to route the mail through another server like your ISP's mail server that will send it on from there on the standard port?

        Feathers
        Just a guess, but one would think you use the port you set your server up with, probably a 'typical' port, here's another guess, you will have to leave it running 24/7/365 or you are going to get some bounced emails, I hope you have a reliable ISP that's ok with the constant connection and bandwidth, they might consider an email server as 'business' and slap some nasty new fees on you. I've thought about doing what you are doing, might turn this machine in to a server when I build my new one.

        Comment


          #5
          Originally posted by tek_heretik View Post
          Just a guess, but one would think you use the port you set your server up with, probably a 'typical' port, here's another guess, you will have to leave it running 24/7/365 or you are going to get some bounced emails, I hope you have a reliable ISP that's ok with the constant connection and bandwidth, they might consider an email server as 'business' and slap some nasty new fees on you. I've thought about doing what you are doing, might turn this machine in to a server when I build my new one.
          Please read what I asked again. Obviously, the software is going to use the port you tell it to - I'm asking whether that port is important or arbitrary, and why.

          The mail server is running on a raspberry Pi; I'm happy to leave it running 24/7/365 because it costs me practically nothing.

          Yep, my ISP is reliable. Since I've been with PlusNet, I haven't ever noticed my connection drop out. A few emails a day is hardly "constant bandwidth" of the type that would make an ISP uneasy.

          They couldn't possibly consider it to be "business" use because I don't own a business or run one from my home, and I use my work's email via webmail for work related emails. Again, the volume of traffic is not very high. I doubt it has even registered with them.

          Try it yourself, it's quite liberating.

          Feathers
          samhobbs.co.uk

          Comment


            #6
            The mail server is running on a raspberry Pi; I'm happy to leave it running 24/7/365 because it costs me practically nothing.
            Thats really cool I would love to do that!

            If you have your server setup, try "nmap" using
            Code:
            nmap -v -A youraddress.com
            or use the IP address.

            It should show you the list of ports.
            Rob

            Comment


              #7
              Originally posted by Robtygart View Post
              Thats really cool I would love to do that!
              Yeah they're amazing little computers. Do you own one? I found Citadel really easy to configure, couldn't get postfix + dovecot + squirrelmail to work completely.

              Thanks for the command but the reason I'm asking is to learn, the server already works perfectly!
              samhobbs.co.uk

              Comment


                #8
                No I haven't even priced one.

                Well the command should tell you what port is open. Best way to learn is to scew around.
                Rob

                Comment


                  #9
                  That's so true! Nice to be able to mess around with something that isn't too important, too.

                  I just bought another one (No.3), with case and charger I paid £43. Not sure how much they are in the US, but it won't be a lot!
                  samhobbs.co.uk

                  Comment


                    #10
                    Nmap is just a port scanner with extras too.. It will not hurt anything.
                    Rob

                    Comment


                      #11
                      @Feathers...I know you are smart, I didn't mean to offend, just throwing a few thoughts out there, after all, this is over and above the usual Kubuntu questions, not that there is anything wrong with that, love your profile pic btw.

                      Comment


                        #12
                        Originally posted by tek_heretik View Post
                        @Feathers...I know you are smart, I didn't mean to offend, just throwing a few thoughts out there, after all, this is over and above the usual Kubuntu questions, not that there is anything wrong with that, love your profile pic btw.
                        Sorry if I over-reacted

                        Glad you know who the character is! Was surprised nobody was using it already, there can't be that many penguins on TV. Apart from real ones.

                        Wallace & Gromit is well known over here, but I know when they made a couple of the recent films they had to change a lot of jokes for the US version because only Brits found them funny... lol. I wonder which version you got in Canada? And how well it was received?

                        Yeah the mail server is a little off topic but luckily Raspbian and Kubuntu are pretty similar to configure.

                        Feathers
                        samhobbs.co.uk

                        Comment


                          #13
                          If your ISP will not allow inbound connections from the Internet to your machine on destination port 25/tcp, then you have no choice but to sign up with a mail relay service. I use Dyn as the registrar for my domain, for relaying outbound mail so that its source is not from a dynamic IP pool, and for accepting inbound email as a gateway for my domain.

                          When someone sends me email, the sender's mail service will query DNS for the MX record associated with my domain. Let's use dig to find out what that might be:
                          Code:
                          steve@t520:~$ [B]dig rileyz.net mx[/B]
                          
                          ; <<>> DiG 9.9.2-P1 <<>> rileyz.net mx
                          ;; global options: +cmd
                          ;; Got answer:
                          ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39525
                          ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 4, ADDITIONAL: 5
                          
                          ;; OPT PSEUDOSECTION:
                          ; EDNS: version: 0, flags:; udp: 4096
                          ;; QUESTION SECTION:
                          ;rileyz.net.                    IN      MX
                          
                          ;; ANSWER SECTION:
                          rileyz.net.             60      IN      MX      20 mx2.mailhop.org.
                          rileyz.net.             60      IN      MX      10 mx1.mailhop.org.
                          The answer is mx{1|2}.mailhop.org. These are Dyn's incoming relay servers. The sender's email will be accepted by one of these.

                          Next, I've configured Dyn's email gateway service to relay incoming messages to my server and to port 2525/tcp:



                          I've configured an A record for my domain because that's also the name of the server; I don't need any "www." or "mail." or whatever:



                          When Dyn's email gateway resolves the IP address of my destination mail server, the answer is the A record above. Then Dyn's email gateway opens a socket to mail-server-ip:2525/tcp and begins the SMTP conversation to deliver my mail.

                          The router behind my cable modem has a rule to forward inbound traffic with destination port 2525/tcp to my Debian 7 server, where Postfix is listening for such inbound connections:
                          Code:
                          root@m92p:~# [B]cat /etc/postfix/master.cf[/B]
                          # =====================================================================
                          # service type  private unpriv  chroot  wakeup  maxproc command + args
                          #               (yes)   (yes)   (yes)   (never) (100)
                          # =====================================================================
                          #smtp      inet  n       -       -       -       -       smtpd
                          2525       inet  n       -       -       -       -       smtpd
                          submission inet  n       -       -       -       -       smtpd
                           -o syslog_name=postfix/submission
                           -o smtpd_tls_security_level=encrypt
                           -o smtpd_sasl_auth_enable=yes
                           -o smtpd_client_restrictions=permit_sasl_authenticated,reject
                           -o milter_macro_daemon_name=ORIGINATING
                          ...
                          You'll notice that Postfix is also listening on 587/tcp, the submission port. That's for when I send outbound mail. My mail clients are configured to send outbound mail via my server, so no matter where I happen to be, outbound mail delivery begins with an inbound connection to my server. My router has a rule that forwards inbound traffic with destination port 587/tcp to the server. The client authenticates and then delivers the outbound mail to my server.

                          Next, the server relays that outbound mail to Dyn:
                          Code:
                          root@m92p:~# [B]cat /etc/postfix/main.cf[/B]
                          ...
                          relayhost = outbound.mailhop.org:2525
                          smtp_sasl_auth_enable = yes
                          smtp_sasl_security_options =
                          smtp_sasl_password_maps = hash:/etc/postfix/smtp_sasl_password_map
                          ...
                          Dyn's relay servers listen for mail on 25/tcp, 2525/tcp, and 10025/tcp. To keep beneath the Comcast radar, I choose 2525/tcp. (The only reason I used 2525/tcp on my own server for inbound mail relayed by Dyn was to keep my brain from melting. They don't really have to match.)

                          The file /etc/postfix/smtp_sasl_password_map contains my user ID and password for the Dyn service. When my mail server relays outbound mail to Dyn, it must authenticate.


                          As you are no doubt learning, email can be one of the thorniest things to get running. I admire your persistence...keep learning!

                          Comment


                            #14
                            Steve,

                            Thank you so much for taking the time to write such an informative post, it's just what I was after!

                            Definitely still learning! Not sure I'll ever stop, there's so much to know and it's so enjoyable making constant progress.

                            Feathers
                            samhobbs.co.uk

                            Comment


                              #15
                              Originally posted by SteveRiley View Post
                              .... I use Dyn as the registrar for my domain...
                              I've purchased a domain name (jlkreps.net) around 2000 and my last activity was in Aug of 2004. It was to put my wife's geneology on for a few years so her family could generate the family tree and link everyone up. When I dropped it porn makers picked it up and I started getting complaints from friends that I was pushing porn! http://www.plotip.com/domain/jlkreps.net Somebody else registered it in 2008.

                              Buying the domain name I still couldn't use it until I bought a hosting service and their DNS service. They set up a server with my domain name on it and set up the DNS also.

                              So, if I read you right, I can set up my laptop, or another computer here at home, purchased a domain name and register it with Dyn, who will then give me an IP address (static?) and DNS connections, bypassing my ISP email service or gmail?
                              "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                              – John F. Kennedy, February 26, 1962.

                              Comment

                              Working...
                              X