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

SMTP support #177

Closed
mkoohafkan opened this issue Feb 28, 2019 · 8 comments
Closed

SMTP support #177

mkoohafkan opened this issue Feb 28, 2019 · 8 comments

Comments

@mkoohafkan
Copy link

Curl apparently supports email sending via SMTP:

curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd --mail-from 'username@gmail.com' --mail-rcpt 'john@example.com' --upload-file mail.txt --user 'username@gmail.com:password'

Where mail.txt has content e.g.

From: "User Name" <username@gmail.com>
To: "John Smith" <john@example.com>
Subject: This is a test

Hi John,
I’m sending this mail with curl thru my gmail account.
Bye!

Is this possible to do with with this package? It seems like most of these options exists, with the exception of --upload-file. There is an upload option in curl_options but it expects an integer value, so I'm not sure how to use it.

@jeroen
Copy link
Owner

jeroen commented Feb 28, 2019

Hmm we would need to mimic this example: https://curl.haxx.se/libcurl/c/smtp-mail.html

@jeroen
Copy link
Owner

jeroen commented Mar 2, 2019

Hmm this is pretty difficult. I support for vector options (that we need for curlopt_mail_rcpt) in the smtp branch:

remotes::install_github("jeroen/curl@smtp")

And then you can try something like this:

library(curl)
h <- new_handle(verbose = TRUE, mail_from = "Sender <sender@ocpu.io>", 
  mail_rcpt = "Jeroen Ooms <jeroenooms@gmail.com>")
con <- file("body.txt", open = 'rb')

handle_setopt(h, readfunction = function(nbytes, ...) {
  cat("reading", nbytes, "bytes\n")
  buf <- readBin(con, raw(), nbytes)
}, upload = TRUE)

res <- curl::curl_fetch_memory('smtp://localhost', handle = h)

But the emails keeps bouncing for me, not sure what I do wrong.

@mkoohafkan
Copy link
Author

Actually, your example worked for me when I used my organization's SMTP server! I didn't try it with gmail or localhost.

@datawookie
Copy link
Contributor

Hi, I've just tried this using Gmail and it worked fine for me! Thanks, Andrew.

@datawookie
Copy link
Contributor

Hi @jeroen, I'm using this feature routinely now. Any chance we can get this merged into master?

@jeroen
Copy link
Owner

jeroen commented Jul 21, 2019

curl::send_mail() is in master

@jeroen jeroen closed this as completed Jul 21, 2019
@jeroen
Copy link
Owner

jeroen commented Jul 26, 2019

Fix in curl 4.0 on CRAN now.

@datawookie
Copy link
Contributor

Brilliant. Thanks.

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