Guest User

Untitled

a guest
Dec 7th, 2018
1,538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. ## Not run:
  2. from <- "<tal.galili@gmail.com>" # sprintf("<sendmailR@\%s>", Sys.info()[4])
  3. to <- "<tal.galili@gmail.com>"
  4. subject <- "Hello from R"
  5. body <- list("It works!", mime_part(iris))
  6. sendmail(from, to, subject, body,
  7. control=list(smtpServer="ASPMX.L.GOOGLE.COM."))
  8.  
  9. Error in socketConnection(host = server, port = port, blocking = TRUE) :
  10. cannot open the connection
  11. In addition: Warning message:
  12. In socketConnection(host = server, port = port, blocking = TRUE) :
  13. smtp.gmail.com tal.galili@gmail.com:statisfun:25 cannot be opened
  14.  
  15. send.mail(from = "tal.galili@gmail.com",
  16. to = "tal.galili@gmail.com",
  17. subject = "Subject of the email",
  18. body = "Body of the email",
  19. smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "tal.galili", passwd = "PASSWORD", ssl = TRUE),
  20. authenticate = TRUE,
  21. send = TRUE)
  22.  
  23. library(sendmailR)
  24.  
  25. # 1 case
  26. from <- sprintf("<sendmailR@%s>", Sys.info()[4])
  27. to <- "<tal.galili@gmail.com>"
  28. subject <- "Hello from R"
  29. msg <- "my first email"
  30. sendmail(from, to, subject, msg,control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
  31.  
  32. # 2 case
  33. from <- sprintf("<tal.galili@gmail.com>", Sys.info()[4])
  34. to <- "<tal.galili@gmail.com>"
  35. subject <- "Hello from R"
  36. msg <- "my first email"
  37. sendmail(from, to, subject, msg,control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
  38.  
  39. SendMail <- function(from="me@my-server.de",to="me@my-server.de",text="Hallo",subject="Sag Hallo",smtp="smtp.my.server.de",user="me.myself.and.i",pw="123"){
  40. require(stringr)
  41. part1 <- "Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
  42. Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
  43. Const cdoAnonymous = 0 'Do not authenticate
  44. Const cdoBasic = 1 'basic (clear-text) authentication
  45. Const cdoNTLM = 2 'NTLM "
  46.  
  47. part2 <- paste(paste("Set objMessage = CreateObject(",'"',"CDO.Message",'"',")" ,sep=""),
  48. paste("objMessage.Subject = ",'"',subject,'"',sep=""),
  49. paste("objMessage.From = ",'"',from,'"',sep=""),
  50. paste("objMessage.To = ",'"',to,'"',sep=""),
  51. paste("objMessage.TextBody = ",'"',text,'"',sep=""),
  52. sep="n")
  53.  
  54. part3 <- paste(
  55. "'==This section provides the configuration information for the remote SMTP server.
  56.  
  57. objMessage.Configuration.Fields.Item _
  58. ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  59.  
  60. 'Name or IP of Remote SMTP Server
  61. objMessage.Configuration.Fields.Item _
  62. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ",'"',smtp,'"',"
  63.  
  64. 'Type of authentication, NONE, Basic (Base64 encoded), NTLM
  65. objMessage.Configuration.Fields.Item _
  66. ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
  67.  
  68. 'Your UserID on the SMTP server
  69. objMessage.Configuration.Fields.Item _
  70. ("http://schemas.microsoft.com/cdo/configuration/sendusername") = ",'"',user,'"',"
  71.  
  72. 'Your password on the SMTP server
  73. objMessage.Configuration.Fields.Item _
  74. ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ",'"',pw,'"', "
  75.  
  76. 'Server port (typically 25)
  77. objMessage.Configuration.Fields.Item _
  78. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  79.  
  80. 'Use SSL for the connection (False or True)
  81. objMessage.Configuration.Fields.Item _
  82. ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
  83.  
  84. 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
  85. objMessage.Configuration.Fields.Item _
  86. ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  87. objMessage.Configuration.Fields.Update
  88.  
  89. '==End remote SMTP server configuration section==
  90.  
  91. objMessage.Send
  92. ",sep="")
  93.  
  94. vbsscript <- paste(part1,part2,part3,sep="nnn")
  95. str_split(vbsscript,"n")
  96. writeLines(vbsscript, "sendmail.vbs")
  97. shell("sendmail.vbs")
  98. unlink("sendmail.vbs")
  99. }
  100.  
  101. SendMail(
  102. from="me.myself@andI.com",
  103. to="whatsup@man.com",
  104. text="Hallo",
  105. subject="readThis",
  106. smtp="smtp.andI.com",
  107. user="me.myself@andI.com",
  108. pw="123456"
  109. )
  110.  
  111. Error in if (code == lcode) { : argument is of length zero
Add Comment
Please, Sign In to add comment