|
| 1 | +import os |
| 2 | + |
| 3 | +import resend |
| 4 | + |
| 5 | +if not os.environ["RESEND_API_KEY"]: |
| 6 | + raise EnvironmentError("RESEND_API_KEY is missing") |
| 7 | + |
| 8 | +f: bytes = open( |
| 9 | + os.path.join(os.path.dirname(__file__), "../resources/resend-wordmark-black.png"), |
| 10 | + "rb", |
| 11 | +).read() |
| 12 | + |
| 13 | +# Send email with local inline attachment |
| 14 | +local_attachment: resend.Attachment = { |
| 15 | + "filename": "resend-wordmark-black.png", |
| 16 | + "content": list(f), |
| 17 | + "content_type": "image/png", |
| 18 | + # This is the content ID that will be used in the HTML to reference the image |
| 19 | + "inline_content_id": "my-test-image", |
| 20 | +} |
| 21 | + |
| 22 | +local_params: resend.Emails.SendParams = { |
| 23 | + "from": "onboarding@resend.dev", |
| 24 | + "to": ["delivered@resend.dev"], |
| 25 | + "subject": "Local inline attachment test from Resend's python SDK", |
| 26 | + "html": '<p>This email contains a local inline attachment: <img width=100 height=40 src="cid:my-test-image" /></p>', |
| 27 | + "attachments": [local_attachment], |
| 28 | +} |
| 29 | + |
| 30 | +local_email: resend.Email = resend.Emails.send(local_params) |
| 31 | +print("Sent email with local inline attachment") |
| 32 | +print(local_email) |
| 33 | + |
| 34 | +# Send email with remote inline attachment |
| 35 | +remote_attachment: resend.RemoteAttachment = { |
| 36 | + "filename": "remote-resend-wordmark-black.png", |
| 37 | + "path": "https://resend.com/static/brand/resend-wordmark-black.png", |
| 38 | + "inline_content_id": "my-test-image", |
| 39 | +} |
| 40 | + |
| 41 | +remote_params: resend.Emails.SendParams = { |
| 42 | + "from": "onboarding@resend.dev", |
| 43 | + "to": ["delivered@resend.dev"], |
| 44 | + "subject": "Remote inline attachment test from Resend's python SDK", |
| 45 | + "html": '<p>This email contains a remote inline attachment: <img width=100 height=40 src="cid:my-test-image" /></p>', |
| 46 | + "attachments": [remote_attachment], |
| 47 | +} |
| 48 | + |
| 49 | +remote_email: resend.Email = resend.Emails.send(remote_params) |
| 50 | +print("Sent email with remote inline attachment") |
| 51 | +print(remote_email) |
0 commit comments