python - Django Email - Define Username and Password -


from documentation, see host, port, username, , password can defined in backend file, want define of them in code itself. can done? if so, how?

from django.core.mail import emailmessage  email = emailmessage(     'hello',     'body goes here',     'from@example.com',     ['to1@example.com', 'to2@example.com'],     ['bcc@example.com'],     reply_to=['another@example.com'],     headers={'message-id': 'foo'}, )  message.attach_file('/images/weather_map.pdf') 

thanks in advance!

update:

i want avoid storing credentials in file. ultimately, want code prompt username , password input variables. update:

i tried this:

import pandas pd django.core.mail import emailmessage django.core.mail.backends.smtp import emailbackend attachment_path=r'c:\path'+'\\'  connection = emailbackend(     host='host',     port=587,     username='login',     password='password' )  email = emailmessage(     'hello',     'body goes here',     'example@example.com',     ['example@example.com'],     ['example@example.com'],     reply_to=['example@example.com'],     headers={'message-id': 'foo'},     connection=connection ) email.attach_file(attachment_path+'attachment.pdf') email.send() 

you can use get_connection instantiate email backend:

from django.core.mail import get_connection  connection = get_connection(     host='...',     port='...',     username='...',     ... ) 

then pass connection when instantiating emailmessage.

email = emailmessage(     'hello',     'body goes here',     'from@example.com',     ['to1@example.com', 'to2@example.com'],     ['bcc@example.com'],     reply_to=['another@example.com'],     headers={'message-id': 'foo'},     connection=connection, ) 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -