7

I try to send an email using the R package blastula. The email should be sent though my employers secure smtp server, but I am stuck with the error "No Kerberos credentials available". A similar setup works in python, but I would like to do it from R, as it fits my workflow better.

The r code used to send the mail, is shown here.

library(blastula)
email <- prepare_test_message()
to <- "receiver_address@gmail.com"
from <- "sender_address@domain.com"

create_smtp_creds_file(
  file = "cred_file",
  user = "username",
  host = "smtps.server.com",
  port = 465,
  use_ssl = TRUE
)
#> Please enter password in TK window (Alt+Tab)
#> The SMTP credentials file (`cred_file`) has been generated

smtp_send(email, to, from, 
          subject = "Hello", 
          credentials = creds_file(file = "cred_file"), 
          verbose = TRUE)
#> Error in curl::curl_fetch_memory(url, handle = h): Failure when receiving data from the peer

Created on 2019-12-10 by the reprex package (v0.3.0)

The verbose output from the smtp_send command is given here:

* Rebuilt URL to: smtps://smtps.server.com:465/
*   Trying xx.xx.xx.xx...
* TCP_NODELAY set
* Connected to smtps.server.com (xx.xx.xx.xx) port 465 (#1)
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*  subject: XXXXXXXX
*  start date: Apr 20 00:00:00 2017 GMT
*  expire date: Apr 23 12:00:00 2020 GMT
*  subjectAltName: host "smtps.server.com" matched cert's "smtps.server.com"
*  issuer: C=NL; ST=Noord-Holland; L=Amsterdam; O=TERENA; CN=TERENA SSL CA 3
*  SSL certificate verify ok.
< 220 mail.server.com Microsoft ESMTP MAIL Service ready at Tue, 10 Dec 2019 12:49:44 +0100
> EHLO henrik-HP-EliteBook-840-G5
< 250-mail.sdu.dk Hello [xx.xx.xx.xx]
< 250-SIZE 62914560
< 250-PIPELINING
< 250-DSN
< 250-ENHANCEDSTATUSCODES
< 250-STARTTLS
< 250-AUTH GSSAPI NTLM LOGIN
< 250-8BITMIME
< 250-BINARYMIME
< 250 CHUNKING
> AUTH GSSAPI
< 334 GSSAPI supported
* gss_init_sec_context() failed: No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_501). 
* Closing connection 1
Error in curl::curl_fetch_memory(url, handle = h) : 
  Failure when receiving data from the peer

And output from sessionInfo()

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               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    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] blastula_0.3.1.9000

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        compiler_3.6.1    prettyunits_1.0.2 remotes_2.1.0     tools_3.6.1       getPass_0.2-2    
 [7] testthat_2.3.1    digest_0.6.23     pkgbuild_1.0.6    uuid_0.1-2        pkgload_1.0.2     jsonlite_1.6     
[13] memoise_1.1.0     rlang_0.4.2       cli_2.0.0         rstudioapi_0.10   commonmark_1.7    curl_4.3         
[19] yaml_2.2.0        xfun_0.11         withr_2.1.2       stringr_1.4.0     knitr_1.26        fs_1.3.1         
[25] desc_1.2.0        devtools_2.2.1    rprojroot_1.3-2   glue_1.3.1        R6_2.4.1          processx_3.4.1   
[31] fansi_0.4.0       sessioninfo_1.1.1 callr_3.4.0       magrittr_1.5      usethis_1.5.1     backports_1.1.5  
[37] ps_1.3.0          ellipsis_0.3.0    htmltools_0.4.0   assertthat_0.2.1  stringi_1.4.3     crayon_1.3.4   
midtiby
  • 14,550
  • 6
  • 34
  • 43

1 Answers1

0

This looks identical to an error I received while trying to use SendGrid as the SMTP service. The issue was not with blastula, but with the fact that I had not verified a "Single Sender Identity".

In the SendGrid UI you will find "Sender Authentication" under settings. Verify the address that you will use as the from address in you blastula message. Once you have clicked on the verification email that you receive in your inbox send again from blastula. The message should now be delivered without issues.

FvD
  • 3,697
  • 1
  • 35
  • 53