Code Monkey home page Code Monkey logo

sendgridr's Introduction

sendgridr

Lifecycle: experimental R-CMD-check send-test CRAN status runiverse-name runiverse-package metacran downloads Downloads

The goal of sendgridr is to mail using r with sendgrid service that provides free 100 mail per day forever.

Installation

# CRAN version
install.packages("sendgridr")

# Dev version
install.packages("sendgridr", repos = "https://mrchypark.r-universe.dev")

Set API key for authentication

You can set api key using auth_set() function. Also auth_check() function check api key works.

auth_check()
auth_set()

Send mail

Example code

Please replace your conditions.

mail() |>
  from("[email protected]", "example name for display") |>
  to("[email protected]", "example name for display 2") |>
  subject("test mail title") |>
  body("hello world!")  |>
  ## attachments is optional
  attachments("report.html") |>
  send()

sg_mail class

mail() function create sg_mail class object and also list. sg_mail class only has print method.

sendproject1 <- mail()
class(sendproject1)
#> [1] "sg_mail" "list"
sendproject1
#> SendGrid Mail - 
#> ✖   from   : (required)
#> ✖   to     : (required)
#> ✖   subject: (required)
#> ✖   content: (required)
#> ✔   attach : (optional)

to, from, subject, body are required. cc, bcc, attachments are optional.

multi- setting using inline

to, cc, bcc, attachments functions are able to set multi values.

library(sendgridr)
mail() |>
  from("[email protected]", "[email protected]") |>
  to("[email protected]", "1 exam") |>
  to("[email protected]", "2 exam") |>
  to("[email protected]", "3 exam") |>
  subject("test mail title") |>
  body("hello world!")
#> SendGrid Mail -
#> ✔   from   : [email protected] <[email protected]>
#> ✔   to     : cnt[3] 1 exam <[email protected]>, 2 exam <toexam2 ...
#> ✔   subject: nchr[15] test mail title
#> ✔   content: nchr[12] hello world!
#> ✔   attach : (optional)

Code of Conduct

Please note that the sendgridr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Keon-Woong Moon
Keon-Woong Moon

🐛
Jinseob Kim
Jinseob Kim

🤔
Carl Ganz
Carl Ganz

🤔
peter-bastian
peter-bastian

🐛
Curtis Petersen
Curtis Petersen

🤔 👀
Amanda Dobbyn
Amanda Dobbyn

💻
Emanuele Guidotti
Emanuele Guidotti

📖 ⚠️ 🐛 💻
Antoine Languillaume
Antoine Languillaume

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

sendgridr's People

Contributors

aedobbyn avatar alanguillaume avatar allcontributors[bot] avatar mrchypark avatar olivroy avatar vincentguyader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sendgridr's Issues

wait for cran udpate

dependency package(emayili) over 0.7.0 but not on cran now. sendgridr also wait for this.

Problem to develop a shinyapp with the sendgrid package

Dear creators,
After asking to hide the kyering package to authenticate myself to the sendgrid api #48.

I tried to develop a shinyapp with the sendgrid dev package installed locally with the following command.

install.packages("sendgridr", repos = "https://mrchypark.r-universe.dev")

but the shiny deploy process, gave me the following error.

Errore: Unhandled Exception: Child Task 1245481735 failed: Error building image: Error fetching sendgridr (0.6.0) source. <CRANPackageSource repo='http://cran.rstudio.org'> unable to satisfy package: sendgridr (0.6.0)
Esecuzione interrotta

How can i solve this?

.JSON files in attachments() are duplicated in sent email...

Including a file with a .json extension in attachments() duplicates the json file in the sent email. So, if I use this syntax below to send an email, it will have three attachment files (instead of the correct two) in the email I receive: File1.json, File1.json and file2.txt.

mail() %>%
@.") %>%
@.
") %>%
subject("See attached files...") %>%
body("Please find attached the files you requested") %>%
attachments("File1.json") %>%
attachments("file2.txt") %>%
send()

Problems with installation

Having some issues installing the package on an Ubuntu machine with R 3.6.0. Any attempts to install from CRAN/Git on a version higher than 0.5.1 results in this error. I can successfully install 0.5.1 from CRAN archive, but anything above this fails due to a keyring errors. I have tried both removing sendgridr completely, as well as keyring completely

For what it's worth, I do have keyring configured correctly (I can even run an auth_check() and get TRUE from sendgridr), but it still will not let me update. I'd honestly prefer to just use a local environment variable, which I see is a feature in the new version, but I am not able to install that version.

In the meantime, I have downgraded to 0.4.3 which uses the environment variable, but seems like if environment variables are an option, reducing the need for a keyring dependency upon installation would be preferable?

* installing *source* packagesendgridr...
** packagesendgridrsuccessfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Warning: replacing previous importpurrr::pluckbyrvest::pluckwhen loadingemayili** help
*** installing help indices
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
Warning: replacing previous importpurrr::pluckbyrvest::pluckwhen loadingemayiliError: package or namespace load failed forsendgridr:
 .onLoad failed in loadNamespace() for 'sendgridr', details:
  call: b__file_set_keyring_pass(self, private, key, keyring)
  error: Aborted setting keyring password
Error: loading failed
Execution halted
ERROR: loading failed
* removing/usr/local/lib/R/site-library/sendgridr* restoring previous/usr/local/lib/R/site-library/sendgridr> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0   

send() seems to fail without a body specification

I have found that send() seems to fail if there is not body specification in the email object. If this is by design, ok. Just want to point this out in case it is a bug.

This code will not send:
email <- sendgridr::mail()
email <- sendgridr::from(email, "[email protected]", "Mail Sender")
email <- sendgridr::to(email, "[email protected]")
email <- sendgridr::subject(email, "Subject")
sendgridr::send(email)

This code does send successfully:
email <- sendgridr::mail()
email <- sendgridr::from(email, "[email protected]", "Mail Sender")
email <- sendgridr::to(email, "[email protected]")
email <- sendgridr::subject(email, "Subject")
email <- sendgridr::body(email, "Body")
sendgridr::send(email)

limitation of content

Limitation of content

Dear package developer,

Thank you for your nice package!

I am one of your big fan from South Korea !!

I have a problem of your package.

Specifically, it seems to me that there is a limitation of content.

The reproducible example:

library(sendgridr)
body=paste0(1:357,collapse="")
mail() %>% 
     from("[email protected]" ) %>% 
     to("[email protected]") %>% 
     subject("Test") %>% 
     content(body)  %>% 
     send()

Error: [ENAMETOOLONG] Failed to stat '1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563

[bug]: Email addresses containing dashes are considered invalid

Reprex

library(sendgridr, warn.conflicts = FALSE)

mail() |>
      from("[email protected]") |>
      to("[email protected]") 
#> Error in to(from(mail(), "[email protected]"), "[email protected]"): please check email address.

Created on 2024-01-03 with reprex v2.0.2

Expected behaviour

"[email protected]" should be considered a

library(sendgridr, warn.conflicts = FALSE)

mail() |>
      from("[email protected]") |>
      to("[email protected]") 
#> SendGrid Mail -
#> ✔   from   : [email protected]
#> ✔   to     : cnt[1] [email protected]
#> ✖   subject: (required)
#> ✖   content: (required)
#> ✔   attach : (optional)

Cause

The error is triggered by the function email_chk()

email_chk("[email protected]")
#> [1] TRUE

email_chk("[email protected]")
#> [1] FALSE

Specifying multiple attachments duplicates files...

I like what your sendgridr package does and very easily allows me to send mail via sendgridr. However, it appears that attachments() has a bug when I attempt to send multiple attachments.

For example, this works as expected, and I get one file in my email:
mail() %>%
from("[email protected]") %>%
to("[email protected]") %>%
subject("See attached files...") %>%
body("Please find attached the files you requested") %>%
attachments("File1.docx") %>%
send()

However, if I want to send multiple attachments, I use this:
mail() %>%
from("[email protected]") %>%
to("[email protected]") %>%
subject("See attached files...") %>%
body("Please find attached the files you requested") %>%
attachments("File1.docx") %>%
attachments("File2.xlsx") %>%
attachments("File3.pptx") %>%
send()

It does send the email, but I get two copies of each attachment.

Please rename content function

The content function can clash with the fairly popular httr::content function. I would recommend either name spacing your functions ie sg_content or thinking of a different name.

Thanks for the wonderful package.

Make keyring use optional

I have many shinyapps and jobs where I need to send emails using sendgridr. In the previous versions, I just had to set the SENDGRID_API environment variable to my key, and the function send would get the key from there. In the new release it is not possible any more, and there is the need to use the prompt to type the password to the keyring. I suggest the following: if the user has the envvar SENDGRID_API set, use that; otherwise, use keyring.

I can make a pull request with that, if you wish! I suggest something like this:

send = function(mail) {
  tar <- "https://api.sendgrid.com/v3/mail/send"
  
  key = Sys.getenv("SENDGRID_API")
  if (nchar(key) == 0) key = auth_key()
  
  ahd <- httr::add_headers(Authorization = paste0("Bearer ", key), `content-type` = "application/json")
  body <- jsonlite::toJSON(mail, auto_unbox = TRUE)
  body <- gsub("personalizations\":", "personalizations\":[", 
               body)
  body <- gsub("},\"subject\"", "}],\"subject\"", body)
  res <- httr::POST(tar, ahd, body = body)
  res <- httr::content(res)
  if (identical(res, raw(0))) {
    res <- list(success = "Send Success!")
  }
  return(res)
}

Error: [ENAMETOOLONG] Failed to stat

Hi there, it is weird but I'm still getting an error when trying to send an email with the body that exceeds 200 characters.
I've updated to sendgridr version 0.4.2 on CRAN.
This is the same as #7

attachment meme type is not good work

I don't want to handy data table for meme type

"application/xml is recommended as of RFC 7303 (section 4.1), but text/xml is still used sometimes. You can assign a specific MIME type to a file with .xml extension depending on how its contents are meant to be interpreted. For instance, an Atom feed is application/atom+xml, but application/xml serves as a valid default."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.