Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34128

Re: send email with bcc

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: send email with bcc
Date 2012-12-01 14:41 -0500
Organization > Bestiaria Support Staff <
References <9fedf732-2a8e-4445-bdce-b88d53f4540c@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.405.1354390881.29569.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, 30 Nov 2012 12:25:37 -0800 (PST), Ed <akegb3@gmail.com>
declaimed the following in gmane.comp.python.general:


> # Start the server:
> smtp.ehlo()
>
	Technically, the server is always running -- this just connects you
(as a CLIENT) to that running server.
 
> # Send the email
> smtp.sendmail(sender, [to] + bcc, msg.as_string())

	I notice that you left OUT the CC addresses.

> 
> The above generates the following error:
> Traceback (most recent call last):
>   File "/opt/batch/ebtest/example4.py", line 46, in <module>
>     smtp.sendmail(sender, [to] + bcc, msg.as_string())

	Pardon --- you failed to include the ERROR, you've only supplied the
traceback identifying which line failed.

	However, presuming the error is

TypeError: can only concatenate list (not "str") to list

then the solution is obvious... DON'T try to use "+" with a string on
one side and a list on the other...

>>> [to] + [cc] + [bcc]
['ed@domain.gov', 'ed@gmailmail.com', 'ed@domain.net']

	But note that this won't work if one of the three is already a list!

>>> bcc = ["ed@domain.net", "someone.else"]
>>> [to] + [cc] + [bcc]
['ed@domain.gov', 'ed@gmailmail.com', ['ed@domain.net', 'someone.else']]

	If you ensure that each address block starts as a list, you can...

>>> to = ["ed@domain.gov"]
>>> cc = ["ed@gmailmail.com"]
>>> bcc = ["ed@domain.net", "someone.else"]
>>> add = []
>>> add.extend(to)
>>> add.extend(cc)
>>> add.extend(bcc)
>>> add
['ed@domain.gov', 'ed@gmailmail.com', 'ed@domain.net', 'someone.else']
>>> 


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

send email with bcc Ed <akegb3@gmail.com> - 2012-11-30 12:25 -0800
  Re: send email with bcc Tim Golden <mail@timgolden.me.uk> - 2012-11-30 20:40 +0000
  Re: send email with bcc Ervin Hegedüs <airween@gmail.com> - 2012-11-30 22:03 +0100
  Re: send email with bcc Ed <akegb3@gmail.com> - 2012-11-30 14:35 -0800
  Re: send email with bcc Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-01 14:41 -0500

csiph-web