Attachments are sent with multipart MIME in SMTP by dividing the message body into multiple parts, each with its own MIME type and headers, and including the attachment as one of these parts.

To send an attachment with SMTP, the message is typically composed using the multipart/mixed MIME type. This MIME type allows for multiple parts, each with its own MIME type, to be included in the message body. The message header includes a boundary parameter that defines a unique string to separate the parts of the message.

The first part of the message is typically a text/plain or text/html part containing the body of the message. This part is followed by one or more parts containing the attachments. Each attachment part has a content-type set to the appropriate MIME type for the attachment file, and a content-disposition header that specifies the filename and the disposition type (attachment or inline).

When the email message is received by the recipient's email client, the multipart/mixed content is parsed, and the body and attachments are displayed accordingly. The email client typically displays the body text in the message body and displays the attachments as separate files or inline content, depending on the content-disposition header.

In summary, sending attachments with SMTP using multipart MIME involves creating a multipart/mixed message with a boundary parameter, adding a text/plain or text/html part for the message body, and adding one or more parts for the attachments, each with its own content-type and content-disposition headers. When the email message is received, the parts are parsed and displayed as appropriate.

NodeMailer Javascript SMTP attachments example

You can send emails with attachments using NodeMailer and Javascript. The following example shows how to send an email with an attachment using NodeMailer and Javascript.

How to send attachments in email with Windows Powershell

Sending attachments via SMTP with bash script

Sending attachments in email Python

Here's a tutorial on how to send attachments in SMTP email using Python's built-in smtplib and email modules:

In this code example, we first import the necessary modules: smtplib, MIMEText, MIMEMultipart, MIMEBase, and encoders. We then create a MIMEMultipart message object and set its attributes, including the sender and recipient email addresses, the subject and body of the email, and the attachment.

Next, we open the file to be attached in binary mode, create a MIMEBase object, and set its attributes, including the file type and name. We then encode the attachment with base64 and attach it to the message object.

We then create a SMTP session with the email server, start TLS for security, authenticate with the email account, and send the email using the sendmail() method. Finally, we terminate the SMTP session.

Note that in this example, we're using a Gmail SMTP server. If you're using a different email provider, you'll need to adjust the SMTP server settings accordingly.