#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Mail sending with a file automatically attached using default mail client


    Hi Everyone...

    Let me introduce myself. My name is Mohan and I am new to this forum. I am trying some thing like this. I run some application and it throws some exception and writes the exception to file. I have a button 'Send Report'. On clicking this button, I need to be able to download the exception file to my local machine and it should open the mail client with 'to:', 'subject:', 'body:', and the downloaded exception file attached. I am able to do till the downloading part. I am not able to invoke the mail client with attachment. Is it possible to do? If so can anyone please let me know how to do it? Given below is the code I am using. Can anyone suggest me please?

    Code for downloading the file:
    #!/usr/bin/python
    from email.message import Message
    from email.header import Header
    import os, cgitb, commands;

    cgitb.enable();

    fullPath = '/var/www/pythonfs2/py/temp';

    print 'Content-type: application/zip'
    print "Content-Disposition: attachment; filename=temp";
    print
    print

    checkfile = commands.getstatusoutput('ls %s' % fullPath);
    extension = fullPath[fullPath.rfind('.') + 1:];

    if (checkfile[0] == 0):
    fsize = os.path.getsize(fullPath);

    if (extension == 'pdf'):
    print 'pdf';

    else:
    Header("Content-type: application/octet-stream");
    Header("Content-Disposition: filename='%s'" % os.path.basename(fullPath));

    Header("Content-length: %s" % fsize);
    Header("Cache-control: private"); #use this to open files directly

    if (fsize > 0):
    with open(fullPath, 'r') as f:
    for line in f:
    if (line != ''):
    print line;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Please use code tags when posting your python code, otherwise it's very hard to read it.

    Like this:

    Code:
    print r'hello world'
    What mail client are you trying to open? What operating system and python version are you using? Are you trying to open the mail client locally or remotely?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by partoj
    Please use code tags when posting your python code, otherwise it's very hard to read it.

    Like this:

    Code:
    print r'hello world'
    What mail client are you trying to open? What operating system and python version are you using? Are you trying to open the mail client locally or remotely?
    I am trying to open mozilla thunderbird.
    I am working on linux (ubuntu).
    I am using python version 2.6.6.
    I am trying to open the mail client locally.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by mudradi.mohan
    I am trying to open mozilla thunderbird.
    I am working on linux (ubuntu).
    I am using python version 2.6.6.
    I am trying to open the mail client locally.
    See this page for starting thunderbird with command line arguments.

    Then I would do something like this:

    Code:
    import commands
    retcode, output = commands.getstatusoutput('thunderbird -compose "to: someone"')
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by partoj
    See this page for starting thunderbird with command line arguments.

    Then I would do something like this:

    Code:
    import commands
    retcode, output = commands.getstatusoutput('thunderbird -compose "to: someone"')
    Thanks a lot for the help. It works fine on my local machine. For example i am writing the mail send script on the server side. When I click the button 'Send Report'(which is actually written on server, from my browser, then is this possible?

    To be more clear,

    I am accessing a page of the server on my local machine, I am clicking the button 'Send Report' which is server code. I am downloading the file to my local machine. So is it possible to invoke my local thunderbird with local attachment on the click of a button written on server? As far as I know, it might not be possible. But still I would like to know whether it is possible or not.

    Thank you
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by mudradi.mohan
    Thanks a lot for the help. It works fine on my local machine. For example i am writing the mail send script on the server side. When I click the button 'Send Report'(which is actually written on server, from my browser, then is this possible?

    To be more clear,

    I am accessing a page of the server on my local machine, I am clicking the button 'Send Report' which is server code. I am downloading the file to my local machine. So is it possible to invoke my local thunderbird with local attachment on the click of a button written on server? As far as I know, it might not be possible. But still I would like to know whether it is possible or not.

    Thank you
    I'm not sure if that would be possible at all, seems like too big a security issue.

    Why not have the server send the mail directly?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by partoj
    I'm not sure if that would be possible at all, seems like too big a security issue.

    Why not have the server send the mail directly?
    Even I was thinking of the same thing

    Thanks lot..

IMN logo majestic logo threadwatch logo seochat tools logo