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 8241433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:50:12+00:00 2026-06-07T20:50:12+00:00

I made a SMTP server using smtpd module in python. I have been able

  • 0

I made a SMTP server using smtpd module in python. I have been able to get emails and store them in a sqlite database, but the problem is that I have no idea how to retrieve them.

I tried using the following code but I’m not sure if it’s reliable.

import smtpd
import asyncore
import sqlite3
import datetime
import dol     # custom module that i have created to do authentication while retrieving the email 
import threading
class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
    print 'Receiving message from:', peer
    print 'Message addressed from:', mailfrom
    print 'Message addressed to  :', rcpttos
    print 'Message length        :', len(data)
    print "Message :",data
    print data.split("\n\n")
    smtp_auth_cursor.execute("SELECT username FROM smtp_auth_table")
    smtp_entry=smtp_auth_cursor.fetchall()
    print smtp_entry
    subject="project"
    for x in smtp_entry:
        x=x[0]
        name=x+"@example.com"
        if x in name:
            print "entry"
            d=datetime.date.today()
            print "entry"
            date=d.strftime("%A %d. %B %Y")
            print date
            time=datetime.datetime.now().strftime("%I:%M %p")
            print time
            rcpt=rcpttos[0]
            try :
                mail_list_cursor.execute("INSERT INTO mail_list VALUES(101,NULL,?,?,?,?,?,?)",(mailfrom,rcpt,subject,data,date,time))
            except sqllite3.Error, e:
                print "Error %s:" % e.args[0]
                return
            print "hasdf"
            return
    return
def __del__(self):
    server.close()

def Smtp_service(ip,port):
    server = CustomSMTPServer(('127.0.0.1', 2035), None)
    server.set_reuse_addr=True
    threading.Thread(target=dol.Mail_retrive,args=(ip,port,1)).start()
    asyncore.loop()

Then I made this authenticating module that authenticates while retrieving emails. Here is where I started getting lost:

class Handler(BaseHTTPRequestHandler):
''' Main class to present webpages and authentication. '''
def do_HEAD(self):
    print "send header101"
    self.send_response(200)
    self.send_header('Content-type', 'text/html')
    self.end_headers()

def do_AUTHHEAD(self):
    print "send header"
    self.send_response(401)
    self.send_header('WWW-Authenticate', 'Basic realm=\"Test\"')
    self.send_header('Content-type', 'text/html')
    self.end_headers()

def authenticate(self):
    conn=sqlite3.connect(smtp_auth_table,isolation_level=None)
    cursor=conn.cursor()
    cursor.execute("SELECT MAX(SNO)FROM smtp_auth_table")
    max_no=cursor.fetchone()
    cursor.execute("SELECT * FROM smtp_auth_table")
    entry=cursor.fetchall()
    passstring=self.headers.getheader('Authorization')
    flag_no=0
    for x in entry:
        setstring=''
        setstring=x[1]+":"+x[2]
        setstring=str(setstring)
        checkstring=base64.b64encode(setstring)
        checkstring="Basic "+checkstring
        if checkstring==passstring:
            return 1
        flag_no=flag_no+1
        if flag_no==max_no:
            return 0


def do_GET(self):
    ''' Present frontpage with user authentication. '''
    if self.headers.getheader('Authorization') == None:
        self.do_AUTHHEAD()
        self.wfile.write('no auth header received')
        pass
    elif self.authenticate():
        self.do_HEAD()
        self.wfile.write(self.headers.getheader('Authorization'))
        self.wfile.write('authenticated!')
        pass
    else:
        self.do_AUTHHEAD()
        self.wfile.write(self.headers.getheader('Authorization'))
        self.wfile.write('not authenticated')
        pass

httpd = SocketServer.TCPServer(("", 10009), Handler)

httpd.serve_forever()

if __name__ == '__main__':
    main()
  • 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-07T20:50:15+00:00Added an answer on June 7, 2026 at 8:50 pm

    SMTP is a transport protocol that is only for sending messages – strictly for delivery. You cannot use it to retrieve messages. You need to implement POP or IMAP on top of your message store so that clients (email programs) can retrieve messages.

    However if your end goal is to simply display messages on a web page; you can use any Python framework to read the message store and display the message body and headers.

    My favorite is Flask for such lightweight tasks.

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

Sidebar

Related Questions

I am trying to send an smtp email through gmail's smtp server using the
I made a page using HTML which have some .jpg files and some .swf
I have a link on a webpage that sends emails out from localhost SMTP
I am creating and sending emails using the System.Net.Mail namespace. The smtp.Send(mailMessage) call is
I made a Web service in which I have a function to count some
I made a UITableViewCell and I have 20 rows in that table in which
I have a C# application which emails out Excel spreadsheet reports via an Exchange
I have an ASP PasswordRecovery module on a page, the code comes up like
I have made some progress and now i am getting this error the message
I have made asp.net webservice in C# to send mail on given mailid as

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.