{"id":2329,"date":"2026-09-25T07:47:44","date_gmt":"2026-09-24T23:47:44","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2329"},"modified":"2026-03-28T13:13:41","modified_gmt":"2026-03-28T13:13:41","slug":"how-to-use-worksheetmailenvelope-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetmailenvelope-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.MailEnvelope in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>MailEnvelope<\/code> property of a <code>Worksheet<\/code> object in Excel VBA is used to control email-related features when sending a worksheet via email. In xlwings, this functionality is accessed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model. The <code>MailEnvelope<\/code> object allows you to customize the email subject, recipients, and message body when using Excel&#8217;s built-in email integration, typically via the <code>SendMail<\/code> method. It is particularly useful for automating email reports directly from an Excel workbook.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax and Parameters<\/strong><br>In xlwings, you access the <code>MailEnvelope<\/code> property via the <code>api<\/code> property of a <code>Worksheet<\/code> object. The basic syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>worksheet.api.MailEnvelope<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns a <code>MailEnvelope<\/code> object, which has several key properties and methods. The most commonly used include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Subject<\/code>: Sets or gets the email subject line as a string.<\/li>\n\n\n\n<li><code>To<\/code>: Sets or gets the primary recipients as a string (multiple addresses can be separated by semicolons).<\/li>\n\n\n\n<li><code>CC<\/code>: Sets or gets the carbon copy recipients as a string.<\/li>\n\n\n\n<li><code>BCC<\/code>: Sets or gets the blind carbon copy recipients as a string.<\/li>\n\n\n\n<li><code>Introduction<\/code>: Sets or gets the introductory text in the email body as a string. This text appears above the worksheet in the email.<\/li>\n\n\n\n<li><code>Item.Send()<\/code>: Sends the email. Note that this method may require an email client (like Outlook) to be configured and running.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These properties are straightforward to set by assigning string values. For example, <code>worksheet.api.MailEnvelope.Subject = \"Monthly Report\"<\/code> sets the subject. The <code>Introduction<\/code> property is especially useful for adding descriptive text.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Example<\/strong><br>Below is a practical xlwings example that sets up and sends a worksheet via email. This assumes you have an active workbook and an email client set up.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active workbook\nwb = xw.books.active\n# Access the first worksheet\nws = wb.sheets&#91;0]\n\n# Access the MailEnvelope property via api\nenvelope = ws.api.MailEnvelope\n\n# Set email properties\nenvelope.Subject = \"Q4 Sales Data\"\nenvelope.To = \"manager@example.com; team@example.com\"\nenvelope.CC = \"supervisor@example.com\"\nenvelope.Introduction = \"Please find the attached Q4 sales report. Key highlights include a 15% increase in revenue.\"\n\n# Optional: Save or update the workbook before sending\nwb.save()\n\n# Send the email\nenvelope.Item.Send()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `MailEnvelope` property of a `Worksheet` object in Excel VBA is used to control email-related fe&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2329","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=2329"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2329\/revisions"}],"predecessor-version":[{"id":3549,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2329\/revisions\/3549"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}