Sending parameters to pythons smtplib

Posted on 2009-12-20
Last Modified: 2013-12-17
I'm using the smtplib library to send emails, but I'd like to use sendmail's -L parameter so that I can assign my own tracking ID in the logs. I can't figure out how to send parameters such as this one with the smtplib library.

The smtp.sendmail() function has 4th and 5th parameters which are optional, but I'm not sure I can use them here.  In my code I have:

     smtp.sendmail(send_from, send_to, msg.as_string(),"-L12345")

but it gives me an error, "5.5.4 - parameter unrecognized".

If somebody has a solution which doesn't use the smtplib library, that's fine, but I need the ability to send attachments, and I couldn't figure out another easy way of doing this.


Question by:midstar
    1 Comment
    LVL 26

    Accepted Solution

    I'm not sure you can do that with smtplib. I'm not even sure that library uses sendmail, I think it just handles the SMTP communication itself, the function having the same name may just be a coincidence.

    The 4th and 5th args are for in the middle of the SMTP conversation (at the MAIL FROM: and RCPT TO: stage), well after sendmail would have to be invoked with your -L param.  The error you're getting, "5.5.4 - parameter unrecognized" is the remote system saying it doesn't understand the "-L12345" because you're trying to pass it to a local process when smtplib is passing it to the remote server as part of the conversation.

    Featured Post

    Too many email signature updates to deal with?

    Are you constantly visiting users’ desks making changes to email signatures? Feel like it’s taking up all of your time? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

    Join & Write a Comment

    Explanation:- SPF = Sender Policy Framework. This is basically a file that can be published with you DNS (Domain Name Service) records, These are the records on the internet that tell everyone else who is. (eg. When an email is se…
    Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
    In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
    In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now