Python Send a message to domain-based email










-1















Trying to send email message using python's smtplib via gmail:



import smtplib

msg = "rn".join([
"From: " + email_host,
"To: " + email_recipient,
"Subject: subject",
"",
email_msg
])
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(email_host, email_pwd)
server.sendmail(email_host, email_recipient, msg)
server.quit()


For popular services such as yandex, yahoo and gmail it works perfect. But it's impossible to send a message to domain-based emails (login@some_domain.com).



What's the problem?










share|improve this question




























    -1















    Trying to send email message using python's smtplib via gmail:



    import smtplib

    msg = "rn".join([
    "From: " + email_host,
    "To: " + email_recipient,
    "Subject: subject",
    "",
    email_msg
    ])
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.ehlo()
    server.starttls()
    server.login(email_host, email_pwd)
    server.sendmail(email_host, email_recipient, msg)
    server.quit()


    For popular services such as yandex, yahoo and gmail it works perfect. But it's impossible to send a message to domain-based emails (login@some_domain.com).



    What's the problem?










    share|improve this question


























      -1












      -1








      -1








      Trying to send email message using python's smtplib via gmail:



      import smtplib

      msg = "rn".join([
      "From: " + email_host,
      "To: " + email_recipient,
      "Subject: subject",
      "",
      email_msg
      ])
      server = smtplib.SMTP('smtp.gmail.com:587')
      server.ehlo()
      server.starttls()
      server.login(email_host, email_pwd)
      server.sendmail(email_host, email_recipient, msg)
      server.quit()


      For popular services such as yandex, yahoo and gmail it works perfect. But it's impossible to send a message to domain-based emails (login@some_domain.com).



      What's the problem?










      share|improve this question
















      Trying to send email message using python's smtplib via gmail:



      import smtplib

      msg = "rn".join([
      "From: " + email_host,
      "To: " + email_recipient,
      "Subject: subject",
      "",
      email_msg
      ])
      server = smtplib.SMTP('smtp.gmail.com:587')
      server.ehlo()
      server.starttls()
      server.login(email_host, email_pwd)
      server.sendmail(email_host, email_recipient, msg)
      server.quit()


      For popular services such as yandex, yahoo and gmail it works perfect. But it's impossible to send a message to domain-based emails (login@some_domain.com).



      What's the problem?







      python email smtp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 7 at 18:00







      phen0menon

















      asked Nov 15 '18 at 12:13









      phen0menonphen0menon

      508921




      508921






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Email services apply restrictions since there's no authentication when you're sending those emails.



          E.g.
          https://support.asperasoft.com/hc/en-us/articles/216128488-How-to-use-Gmail-as-an-SMTP-relay-for-notification-testing




          This SMTP server does not require TLS or authentication. It is
          restricted because emails can only be sent to other Gmail addresses or
          Google apps users--therefore it may only make sense for testing within
          an internal network that uses Gmail or Google apps. Limits apply per
          recipient.




          I.e. these services don't mind sending emails within their own domain, but don't want malicious users sending to other domains.






          share|improve this answer























          • The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

            – phen0menon
            Nov 15 '18 at 12:31











          • depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

            – richflow
            Nov 15 '18 at 12:39


















          0














          Well, searching for the answer, I found out that Google Mail service doesn't allow to send messages to domain-based emails via 587 SMTP port, because it requires to use TLS.



          enter image description here



          I decided to switch onto 465 SMTP port as said in this post, so it works now perfect! Also, for testing purposes, I used another Mail Service (Yandex), which supports only 465 SMTP port - it works as well.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319259%2fpython-send-a-message-to-domain-based-email%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Email services apply restrictions since there's no authentication when you're sending those emails.



            E.g.
            https://support.asperasoft.com/hc/en-us/articles/216128488-How-to-use-Gmail-as-an-SMTP-relay-for-notification-testing




            This SMTP server does not require TLS or authentication. It is
            restricted because emails can only be sent to other Gmail addresses or
            Google apps users--therefore it may only make sense for testing within
            an internal network that uses Gmail or Google apps. Limits apply per
            recipient.




            I.e. these services don't mind sending emails within their own domain, but don't want malicious users sending to other domains.






            share|improve this answer























            • The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

              – phen0menon
              Nov 15 '18 at 12:31











            • depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

              – richflow
              Nov 15 '18 at 12:39















            0














            Email services apply restrictions since there's no authentication when you're sending those emails.



            E.g.
            https://support.asperasoft.com/hc/en-us/articles/216128488-How-to-use-Gmail-as-an-SMTP-relay-for-notification-testing




            This SMTP server does not require TLS or authentication. It is
            restricted because emails can only be sent to other Gmail addresses or
            Google apps users--therefore it may only make sense for testing within
            an internal network that uses Gmail or Google apps. Limits apply per
            recipient.




            I.e. these services don't mind sending emails within their own domain, but don't want malicious users sending to other domains.






            share|improve this answer























            • The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

              – phen0menon
              Nov 15 '18 at 12:31











            • depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

              – richflow
              Nov 15 '18 at 12:39













            0












            0








            0







            Email services apply restrictions since there's no authentication when you're sending those emails.



            E.g.
            https://support.asperasoft.com/hc/en-us/articles/216128488-How-to-use-Gmail-as-an-SMTP-relay-for-notification-testing




            This SMTP server does not require TLS or authentication. It is
            restricted because emails can only be sent to other Gmail addresses or
            Google apps users--therefore it may only make sense for testing within
            an internal network that uses Gmail or Google apps. Limits apply per
            recipient.




            I.e. these services don't mind sending emails within their own domain, but don't want malicious users sending to other domains.






            share|improve this answer













            Email services apply restrictions since there's no authentication when you're sending those emails.



            E.g.
            https://support.asperasoft.com/hc/en-us/articles/216128488-How-to-use-Gmail-as-an-SMTP-relay-for-notification-testing




            This SMTP server does not require TLS or authentication. It is
            restricted because emails can only be sent to other Gmail addresses or
            Google apps users--therefore it may only make sense for testing within
            an internal network that uses Gmail or Google apps. Limits apply per
            recipient.




            I.e. these services don't mind sending emails within their own domain, but don't want malicious users sending to other domains.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 '18 at 12:18









            richflowrichflow

            928211




            928211












            • The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

              – phen0menon
              Nov 15 '18 at 12:31











            • depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

              – richflow
              Nov 15 '18 at 12:39

















            • The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

              – phen0menon
              Nov 15 '18 at 12:31











            • depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

              – richflow
              Nov 15 '18 at 12:39
















            The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

            – phen0menon
            Nov 15 '18 at 12:31





            The problem is that I cannot send a message to domain-based email via smtp gmail. How to find out solution?

            – phen0menon
            Nov 15 '18 at 12:31













            depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

            – richflow
            Nov 15 '18 at 12:39





            depends on the service, but for example gmail will require authentication if you want to use their SMTP server: support.google.com/a/answer/176600?hl=en . Namely: "Your full Gmail or G Suite email address is required for authentication." and "Port 465 (SSL required) Port 587 (TLS required) Dynamic IPs allowed"

            – richflow
            Nov 15 '18 at 12:39













            0














            Well, searching for the answer, I found out that Google Mail service doesn't allow to send messages to domain-based emails via 587 SMTP port, because it requires to use TLS.



            enter image description here



            I decided to switch onto 465 SMTP port as said in this post, so it works now perfect! Also, for testing purposes, I used another Mail Service (Yandex), which supports only 465 SMTP port - it works as well.






            share|improve this answer



























              0














              Well, searching for the answer, I found out that Google Mail service doesn't allow to send messages to domain-based emails via 587 SMTP port, because it requires to use TLS.



              enter image description here



              I decided to switch onto 465 SMTP port as said in this post, so it works now perfect! Also, for testing purposes, I used another Mail Service (Yandex), which supports only 465 SMTP port - it works as well.






              share|improve this answer

























                0












                0








                0







                Well, searching for the answer, I found out that Google Mail service doesn't allow to send messages to domain-based emails via 587 SMTP port, because it requires to use TLS.



                enter image description here



                I decided to switch onto 465 SMTP port as said in this post, so it works now perfect! Also, for testing purposes, I used another Mail Service (Yandex), which supports only 465 SMTP port - it works as well.






                share|improve this answer













                Well, searching for the answer, I found out that Google Mail service doesn't allow to send messages to domain-based emails via 587 SMTP port, because it requires to use TLS.



                enter image description here



                I decided to switch onto 465 SMTP port as said in this post, so it works now perfect! Also, for testing purposes, I used another Mail Service (Yandex), which supports only 465 SMTP port - it works as well.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 18 '18 at 11:14









                phen0menonphen0menon

                508921




                508921



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319259%2fpython-send-a-message-to-domain-based-email%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3