Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:50:50+00:00 2026-06-17T17:50:50+00:00

Update Figured out why, gmail offers smtp servers on port 465 and 587, 465

  • 0

Update Figured out why, gmail offers smtp servers on port 465 and 587, 465 is SSL and 587 is TLS and ESMTP wants TLS which is why it doesn’t work with 465, the ssl server… I think (I do know it works I am just not definite on why if anyone can explain why please do :))


I am trying to send a email using SMTP and Twisted and nothing happens, no errors, no output, and no email…..

Output

MacBookPro:EmailSender User$ python send_mime_email.py 
What is your email address? [REMOVED]@gmail.com
What is your username (typically same as email address)? [REMOVED]@gmail.com
What is your password? [REMOVED]
What is your smtp server details? smtp.gmail.com:465
-------Email Details-------
Subject: Hello
Body: Hi, how are you?
Attachment: FTP_Commands.txt
-------Logging-------
2013-01-20 20:43:44-0500 [-] Log opened.
2013-01-20 20:43:44-0500 [-] Creating email
2013-01-20 20:43:44-0500 [-] Created Message.
2013-01-20 20:43:44-0500 [-] Starting factory <twisted.mail.smtp.ESMTPSenderFactory instance at 0xa3c508>
2013-01-20 20:43:44-0500 [-] Sending Email
2013-01-20 20:53:44-0500 [ESMTPSender,client] SMTP Client retrying server. Retry: 5
^C2013-01-20 20:54:47-0500 [-] Received SIGINT, shutting down.
2013-01-20 20:54:47-0500 [ESMTPSender,client] SMTP Client retrying server. Retry: 4
2013-01-20 20:54:47-0500 [-] Main loop terminated.

Code

import sys
import email
import email.mime.application

import sys

from OpenSSL.SSL import SSLv3_METHOD

from twisted.mail.smtp import ESMTPSenderFactory
from twisted.internet.ssl import ClientContextFactory
from twisted.internet.defer import Deferred
from twisted.internet import reactor
from twisted.python import log

try:
    from cStringIO import cStringIO as StringIO
except ImportError:
    from StringIO import StringIO


def create_email(address, subject, body, data):
    print "Creating email"
    # email block

    # text body
    msg = email.mime.Multipart.MIMEMultipart()
    msg['Subject'] = subject

    # send it to ourselves to make it simple
    msg['From'] = address
    msg['To'] = address

    # body
    body = email.mime.Text.MIMEText(body)
    msg.attach(body)
    att = email.mime.application.MIMEApplication(data, _subtype="binary")
    att.add_header('Content-Disposition','attachment',filename="data.bin")
    msg.attach(att)

    print "Created Message."

    # Create a context factory which only allows SSLv3 and does not verify
    # the peer's certificate.
    return str(msg)

def send_email(smtp_server, smtp_port, username, password, from_, to, msg):


    contextFactory = ClientContextFactory()
    contextFactory.method = SSLv3_METHOD

    resultDeferred = Deferred()

    mime_obj = StringIO(str(msg))

    senderFactory = ESMTPSenderFactory(
                                       username,
                                       password,
                                       from_,
                                       to,
                                       mime_obj,
                                       resultDeferred,
                                       contextFactory=contextFactory)

    reactor.connectTCP(smtp_server, smtp_port, senderFactory)
    print "Sending Email"
    return resultDeferred



if __name__ == '__main__':
    email_address = raw_input("What is your email address? ")
    username      = raw_input("What is your username (typically same as email address)? ")
    password      = raw_input("What is your password? ")
    sd            = raw_input("What is your smtp server details? ")
    ss, sp        = sd.split(":")
    sp            = int(sp)
    print "-------Email Details-------"
    subject = raw_input("Subject: ")
    body    = raw_input("Body: ")
    attachment_file = raw_input("Attachment: ")
    o = open(attachment_file, "rb")
    data = o.read()
    o.close()
    print "-------Logging-------"

    log.startLogging(sys.stdout)
    email_data = create_email(email_address, subject, body, data)
    send_email(ss, sp, username, password, email_address, email_address, email_data)
    reactor.run()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:50:51+00:00Added an answer on June 17, 2026 at 5:50 pm

    There’s some tricky, confusing terminology confusing things here, I think. “SSL” and “TLS” are actually most commonly used as different names for the same thing. Being slightly stricter about vocabulary (perhaps still not absolutely technically correct though), there is a protocol named “SSLv2” and another protocol named “SSLv3” (an update to SSLv2) and another protocol named “TLSv1” (an update to SSLv3).

    Many people say “SSL” to refer to any of these three things, or perhaps all of them.

    Also, many people say “TLS” to refer to any of these three things, or perhaps all of them!

    Also, there is a separate notion of starting to speak one of these protocols on an established connection which has already been used to exchange some (non-encrypted) data. Sometimes that is what people mean when they say “TLS”, it’s what you mean when you say “TLS” at the top of your question.

    What gmail offers on port 465 is an SMTP server with mandatory SSL (either SSLv2, SSLv3, or TLSv1, I haven’t checked which) which begins at the very beginning of the connection – ie, before any SMTP traffic has been exchanged.

    What gmail offers on port 587 is an SMTP server without any SSL (any of SSLv2, SSLv3, or TLSv1) but which supports the SMTP feature for negotiating a switch to turn on SSL at some point later on.

    The difference here as far as clients are concerned, of course, is whether they should start an SSL (SSLv2, SSLv3, or TLSv1) as soon as the TCP connection is established or if they should instead begin speaking SMTP and then perhaps later negotiate an “upgrade” to SSL (SSLv2, SSLv3, or TLSv1).

    If the client and the server disagree about what exactly should happen here, the result can be a “hung” connection – eg, with the server waiting for the client to start an SSL handshake and the client waiting for the server to send it an SMTP greeting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: OK I figured it out, looks like fread has a filesize limitation, changed
Update II I Figured this out. When using google maps api, the model must
I tried solving my problem using this link update - I figured out that
UPDATE I figured it out. Check out my answer below . I'm trying to
UPDATE: Figured out some stuff and changed code. When I add my NSDictionary to
UPDATE : Figured it out.. The objects I was passing to the ValidatorHookupControl were'nt
Update: I figured it out! Kind of... I'm not sure how this fixed it,
Update: I figured it out. See my answer below. I'm trying to write some
Important update: I already figured out the answers and put them in this simple
I've been trying to figure out a way to update the interface after each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.