Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Aug 2004

    How to send an image with attachment in email


    I want to send an email with image attachement but it doesnt work, i am using the following code given in forum

    import os, rfc822, socket, time, whrandom
    # parameters
    orig = 'principal@myssec.com'
    dest = 'krtrivedi@gmail.com'
    server = 'smtp.myssec.com' # SMTP server address for dest
    subject = 'your image'
    text = 'here you go...'
    image = 'c:\\nokia\\images\\Image(02).jpg'
    mimetype = 'image/jpeg'
    domain = 'myssec.com'
    # send mail with image attached
    filename = os.path.basename(image)
    data = open(image, 'rb').read()
    now = time.time()
    date = rfc822.formatdate(now)
    number = whrandom.randint(0, 0xffffff)
    msgid = '<%X.%X@%s>' % (now, number, domain)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print 'connecting to SMTP server...'
    s.connect((server, 25))
    print 'sending headers...'
    f = s.makefile()
    assert f.readline().startswith('2')
    print >>f, 'helo', domain
    assert f.readline().startswith('2')
    print >>f, 'mail from:', orig
    assert f.readline().startswith('2')
    print >>f, 'rcpt to:', dest
    assert f.readline().startswith('2')
    print >>f, 'data'
    assert f.readline().startswith('3')
    print >>f, 'Message-ID:', msgid
    print >>f, 'Date:', date
    print >>f, 'From:', orig
    print >>f, 'MIME-Version: 1.0'
    print >>f, 'To:', dest
    print >>f, 'Subject:', subject
    boundary = '------' + date.encode('hex')
    print >>f, 'Content-Type: multipart/mixed; boundary="%s"' % boundary
    print >>f
    print >>f, 'This is a multi-part message in MIME format.'
    print >>f, '--' + boundary
    print >>f, 'Content-Type: text/plain; charset=utf-8'
    print >>f
    print >>f, text
    print >>f, '--' + boundary
    print >>f, 'Content-Type: %s; name="%s"' % (mimetype, filename)
    print >>f, 'Content-Transfer-Encoding: base64'
    print >>f, 'Content-Disposition: attachment; filename="%s"' % filename
    print >>f
    print 'sending data...'
    print >>f, data.encode('base64')
    print >>f, '--' + boundary + '--'
    print >>f
    print >>f, '.'
    assert f.readline().startswith('2')
    print >>f, 'quit'
    print '%d bytes image sent in %d s' % (len(data), time.time() - now)
    ||Kiran ||
    Nokia E-65
    Nokia 7610
    Nokia N95 8GB
    Nokia E90
    Nokia 5110 !!
    Nokia 6110i !!

  2. #2
    Super Contributor
    Join Date
    May 2006
    Oulu, Finland

    Re: How to send an image with attachment in email

    Hello krtrivdi

    I tried it on my phone but it cannot reach the smtp server

    Also tracert gives:
    ...>tracert smtp.myssec.com
    Unable to resolve target system name smtp.myssec.com.
    Ping gives
    ...>ping smtp.myssec.com
    Ping request could not find host smtp.myssec.com. Please check the name and try again.
    So if you are using the same smtp server at your institute, check with your network administrator that it's not only for an intranet since we are able to reach the pages from http.//myssec.com

    To be sure I ran nmap on a linux machine that confirmed me that the port 25 is not open on myssec.com

    Here's the output:
    root@pboltest:~# nmap -sT -O myssec.com
    Starting Nmap 4.10 ( http://www.insecure.org/nmap/ ) at 2007-01-09 13:58 EET
    Interesting ports on 72-29-64-39.static.dimenoc.com (
    Not shown: 1600 filtered ports, 65 closed ports
    1/tcp    open  tcpmux
    21/tcp   open  ftp
    22/tcp   open  ssh
    53/tcp   open  domain
    80/tcp   open  http
    110/tcp  open  pop3
    143/tcp  open  imap
    443/tcp  open  https
    465/tcp  open  smtps
    993/tcp  open  imaps
    995/tcp  open  pop3s
    1720/tcp open  H.323/Q.931
    3306/tcp open  mysql
    6666/tcp open  irc-serv
    Device type: firewall|general purpose
    Running: IPCop Linux 2.4.X, Linux 2.4.X|2.6.X
    OS details: IPCop 1.4 - 1.4.6 Linux 2.4.2x-based firewall, Linux 2.4.20 - 2.4.22                       , Linux 2.6.10 - 2.6.11

    Last edited by lfd; 2007-01-09 at 15:18.
    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:

Similar Threads

  1. Send email automatically without any user interaction? (s60v3)
    By zhengy in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2006-08-12, 19:37
  2. Replies: 0
    Last Post: 2006-02-07, 14:59
  3. how to send an image to moblie OR what formats are supported
    By omo_5 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2006-01-01, 15:38
  4. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  5. Send an image from the 7650 to a laptop using Bluetooth
    By dgilders in forum Bluetooth Technology
    Replies: 2
    Last Post: 2002-10-14, 22:49

Posting Permissions

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