Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending attachments with the email sender #1369

Open
andreleblanc11 opened this issue Jan 15, 2025 · 0 comments
Open

Sending attachments with the email sender #1369

andreleblanc11 opened this issue Jan 15, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request likely-fixed likely fix is in the repository, success not confirmed yet. NewUseCase needed to address a use case, we can't yet support. Sugar nice to have features... not super important.

Comments

@andreleblanc11
Copy link
Member

andreleblanc11 commented Jan 15, 2025

Currently the email sender isn't able to send images or byte files.

2025-01-15 17:32:38,752 [INFO] sarracenia.flowcb.log after_accept accepted: (lag: 3.83 )  exchange: xpublic subtopic: 20250115.ECONET-STATS.econet a file with baseUrl: http://econet.cmc.ec.gc.ca relPath: 20250115/ECONET-STATS/econet/Econet.jpg id: jigQqY7 size: 799141
2025-01-15 17:32:38,756 [ERROR] sarracenia.flowcb.send.email send Failed to read /apps/sarra/public_data/20250115/ECONET-STATS/econet/Econet.jpg, can't send
 to ['my-email']

We have a use case where we would want the email sender to be able to send images as attachments.
We could probably do this with a new option email_attachment. When True, send the file as an attachment.

I was able to send an email with the JPG mentionned up top with the following code

import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
file = '/apps/sarra/public_data/20250115/ECONET-STATS/econet/Econet.jpg'
msg = MIMEMultipart()
msg['Subject'] = 'subject'
msg['From'] = "[email protected]"
msg['To'] = 'my-email'
text = MIMEText("test")
msg.attach(text)
with open(file, 'rb') as f:
    img_data = f.read()

image = MIMEImage(img_data, name=os.path.basename(file))
msg.attach(image)
s = smtplib.SMTP('mail-server')
s.sendmail(msg['From'], msg['To'], msg.as_string())
@andreleblanc11 andreleblanc11 added enhancement New feature or request NewUseCase needed to address a use case, we can't yet support. Sugar nice to have features... not super important. labels Jan 15, 2025
andreleblanc11 added a commit that referenced this issue Jan 16, 2025
@andreleblanc11 andreleblanc11 self-assigned this Jan 16, 2025
petersilva pushed a commit that referenced this issue Jan 16, 2025
@andreleblanc11 andreleblanc11 added the likely-fixed likely fix is in the repository, success not confirmed yet. label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request likely-fixed likely fix is in the repository, success not confirmed yet. NewUseCase needed to address a use case, we can't yet support. Sugar nice to have features... not super important.
Projects
None yet
Development

No branches or pull requests

1 participant