@@ -182,7 +182,15 @@ ESP send options (AnymailMessage)
182182 :class: `AnymailMessageMixin ` objects. Unlike the attributes above,
183183 they can't be used on an arbitrary :class: `~django.core.mail.EmailMessage `.)
184184
185- .. method :: attach_inline_image(content, subtype=None, idstring="img", domain=None)
185+ .. method :: attach_inline_image_file(path, subtype=None, idstring="img", domain=None)
186+
187+ Attach an inline (embedded) image to the message and return its :mailheader: `Content-ID `.
188+
189+ This calls :func: `attach_inline_image_file ` on the message. See :ref: `inline-images `
190+ for details and an example.
191+
192+
193+ .. method :: attach_inline_image(content, filename=None, subtype=None, idstring="img", domain=None)
186194
187195 Attach an inline (embedded) image to the message and return its :mailheader: `Content-ID `.
188196
@@ -303,9 +311,17 @@ ESP send status
303311Inline images
304312-------------
305313
306- Anymail includes a convenience function to simplify attaching inline images to email.
314+ Anymail includes convenience functions to simplify attaching inline images to email.
315+
316+ These functions work with *any * Django :class: `~django.core.mail.EmailMessage ` --
317+ they're not specific to Anymail email backends. You can use them with messages sent
318+ through Django's SMTP backend or any other that properly supports MIME attachments.
319+
320+ (Both functions are also available as convenience methods on Anymail's
321+ :class: `~anymail.message.AnymailMessage ` and :class: `~anymail.message.AnymailMessageMixin `
322+ classes.)
307323
308- .. function :: attach_inline_image (message, content , subtype=None, idstring="img", domain=None)
324+ .. function :: attach_inline_image_file (message, path , subtype=None, idstring="img", domain=None)
309325
310326 Attach an inline (embedded) image to the message and return its :mailheader: `Content-ID `.
311327
@@ -315,23 +331,20 @@ Anymail includes a convenience function to simplify attaching inline images to e
315331 .. code-block :: python
316332
317333 from django.core.mail import EmailMultiAlternatives
318- from anymail.message import attach_inline_image
319-
320- # read image content -- be sure to open the file in binary mode:
321- with f = open (" path/to/picture.jpg" , " rb" ):
322- raw_image_data = f.read()
334+ from anymail.message import attach_inline_image_file
323335
324336 message = EmailMultiAlternatives( ... )
325- cid = attach_inline_image (message, raw_image_data )
337+ cid = attach_inline_image_file (message, ' path/to/picture.jpg ' )
326338 html = ' ... <img alt="Picture" src="cid:%s "> ...' % cid
327- message.attach_alternative(html, " text/html" )
339+ message.attach_alternative(html, ' text/html' )
328340
329341 message.send()
330342
331343
332344 `message ` must be an :class: `~django.core.mail.EmailMessage ` (or subclass) object.
333345
334- `content ` must be the binary image data (e.g., read from a file).
346+ `path ` must be the pathname to an image file. (Its basename will also be used as the
347+ attachment's filename, which may be visible in some email clients.)
335348
336349 `subtype ` is an optional MIME :mimetype: `image ` subtype, e.g., `"png" ` or `"jpg" `.
337350 By default, this is determined automatically from the content.
@@ -342,14 +355,23 @@ Anymail includes a convenience function to simplify attaching inline images to e
342355 (But be aware the default `domain ` can leak your server's local hostname
343356 in the resulting email.)
344357
345- This function works with *any * Django :class: `~django.core.mail.EmailMessage ` --
346- it's not specific to Anymail email backends. You can use it with messages sent
347- through Django's SMTP backend or any other that properly supports MIME attachments.
348358
349- (This function is also available as the
350- :meth: `~anymail.message.AnymailMessage.attach_inline_image ` method
351- on Anymail's :class: `~anymail.message.AnymailMessage ` and
352- :class: `~anymail.message.AnymailMessageMixin ` classes.)
359+ .. function :: attach_inline_image(message, content, filename=None, subtype=None, idstring="img", domain=None)
360+
361+ This is a version of :func: `attach_inline_image_file ` that accepts raw
362+ image data, rather than reading it from a file.
363+
364+ `message ` must be an :class: `~django.core.mail.EmailMessage ` (or subclass) object.
365+
366+ `content ` must be the binary image data
367+
368+ `filename ` is an optional `str ` that will be used as as the attachment's
369+ filename -- e.g., `"picture.jpg" `. This may be visible in email clients that
370+ choose to display the image as an attachment as well as making it available
371+ for inline use (this is up to the email client). It should be a base filename,
372+ without any path info.
373+
374+ `subtype `, `idstring ` and `domain ` are as described in :func: `attach_inline_image_file `
353375
354376
355377.. _send-defaults :
0 commit comments