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

Email body as attachment #11

Open
aghaynes opened this issue Dec 18, 2023 · 7 comments
Open

Email body as attachment #11

aghaynes opened this issue Dec 18, 2023 · 7 comments

Comments

@aghaynes
Copy link

Hi,

I've been using your package for a while to send emails with HTML body and PDF attachments for a while now. I updated R last week and found that the body is now sent as an attachment too...

I assume that somewhen recently the disposition argument to mime_part has stopped working correctly?

This is essentially the code i've been using...

sendmailR::sendmail(from = address,
                      to = recipient,
                      subject = subject,
                      msg = list(sendmailR::mime_part(emailbody,
                                                      type = "text/html",
                                                      disposition="inline"),
                                 sendmailR::mime_part(pdfoutfile,
                                                      name = pdf_name)),
                      control = smtp_settings)
@aghaynes
Copy link
Author

Some additional info for you...

I rolled back the version of sendmailR that i'm using. Version 1.3-1 behaves as I expect (the body of the email is indeed the body), while the two newer versions (1.3-2 and the current 1.4-0) both include the body as an attachment. Maybe that gives a clue as to what wrong. It at least narrows it down to something that changed within the last 12 ca months.

@ndevln
Copy link
Contributor

ndevln commented Jan 17, 2024

Hi,

around this time, there were some UTF-8 compatibility updates for Outlook.

I am not sure why this happens and it depends on the length and type of emailbody. Could you test if the new mime_part_html() function fixes your problem? This function overwrites the file attachment behavior.

@aghaynes
Copy link
Author

Just to clarify, you mean this?

sendmailR::sendmail(from = address,
                      to = recipient,
                      subject = subject,
                      msg = list(sendmailR::mime_part_html(emailbody),
                                 sendmailR::mime_part(pdfoutfile,
                                                      name = pdf_name)),
                      control = smtp_settings)

Yes, I can try that out tomorrow.

@ndevln
Copy link
Contributor

ndevln commented Jan 17, 2024

But if you provide more details or a working example for emailbody, I can try to find out, why this text is wrongly classified as an attachment.

@aghaynes
Copy link
Author

I'll see if i can do one tomorrow... I can't share the actual emails...

@aghaynes
Copy link
Author

Using mime_part_html works - the email body is indeed displayed as the body. Thanks for the tip! :)

The body that is wrongly included as an attachment with mime_part is an Rmd compiled to html. I tried with the default template one from RStudio and that is also treated as an attachment (github wont let me share the compiled html, so here's the Rmd code).

---
title: "Untitled"
author: "Author"
date: "2022-11-29"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
#| result: hide
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

@chrisumphlett
Copy link

chrisumphlett commented Feb 12, 2024

I'm having the opposite problem -- the attachment is being written to the body, and results in this overflow error:

## I have from, to, subject, attachmentname defined elsewhere
data(iris)
vroom::vroom_write(iris, file = attachmentName, delim = ",")
subject <- "Hello from R"
body <- list(mime_part("It works!"), mime_part(x=attachmentName))
sendmail(from, to, subject, body,
         control=list(smtpServer="corpsmtp.techsmith.com"))

Error in wait_for(250) : 
  SMTP Error: maximum allowed line length is 998 octets, got 5093

cars because it's smaller works (no error, the email sends). but it puts it in the body and is unintelligible

vroom::vroom_write(cars, file = attachmentName, delim = ",")
subject <- "Hello from R"
body <- list(mime_part("It works!"), mime_part(x=attachmentName))
sendmail(from, to, subject, body,
         control=list(smtpServer="corpsmtp.techsmith.com"))

$code
[1] "221"

$msg
[1] "mail3.techsmith.com closing connection"

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants