question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Send Email with Attachment

See original GitHub issue

Im getting a False response from m.sendMessage() when using attachments and I have no idea why. The print statement returns False when the following lines are removed it sends fine;

att = Attachment(path=filepath)
m.attachments.append(att)

example function

def email_message(username, password, dir_path):
	try:
		filepath = dir_path + '/filename_{}.csv'.format(str(now))
		authenticiation = (username, password)
		m = Message(auth=authenticiation)
		att = Attachment(path=filepath)
		m.attachments.append(att)
		m.setRecipients("emailhere@address.com")
		m.setSubject("Subject")
		m.setBody("Testing")
		sent = m.sendMessage()
		print sent

	except Exception, e:
		traceback.print_exc()
		print 'Sending Email Failed'
		print e
		return False

	return sent

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Narcolapsercommented, Nov 10, 2016

Found it. I was using “encodebytes” to do the B64 encoding, but that method isn’t available in python 2. Fix coming soon.

0reactions
silverstar194commented, Jan 24, 2018

@sampellino used your workaround to attach. The library still seems to be broken for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Write an Email With an Attachment (With Examples)
1. Determine what files you wish to send · 2. Write the email's subject line · 3. Compose the email's body · 4....
Read more >
How to Send an Email with an Attachment (for Beginners)
But people who are new to email might not yet know how to attach and send files in email. Here are some beginner...
Read more >
Add email attachments in Mail on iPhone - Apple Support
Attach a photo, video, or document to an email · Attach a document: Tap the Insert Attachment button above the keyboard, then locate...
Read more >
How to Craft The Perfect Email with Attachments (Examples ...
An email attachment is a file accompanying an outgoing email that provides additional content not covered in your email body. The extra ...
Read more >
JavaMail API - Sending Email With Attachment - Tutorialspoint
Here is an example to send an email with attachment from your machine. The file on local machine is file.txt placed at /home/manisha/....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found