Guest User

Untitled

a guest
Jan 17th, 2018
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. library(sendmailR)
  2.  
  3. #set working directory
  4. setwd("C:/workingdirectorypath")
  5.  
  6. #####send plain email
  7.  
  8. subject <- "Email Subject"
  9. body <- "Email body."
  10. mailControl=list(smtpServer="serverinfo")
  11.  
  12. sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)
  13.  
  14. #####send same email with attachment
  15.  
  16. #needs full path if not in working directory
  17. attachmentPath <- "subfolder/log.txt"
  18.  
  19. #same as attachmentPath if using working directory
  20. attachmentName <- "log.txt"
  21.  
  22. #key part for attachments, put the body and the mime_part in a list for msg
  23. attachmentObject <- mime_part(x=attachmentPath,name=attachmentName)
  24. bodyWithAttachment <- list(body,attachmentObject)
  25.  
  26. sendmail(from=from,to=to,subject=subject,msg=bodyWithAttachment,control=mailControl)
  27.  
  28. attachmentObject <- mime_part(x="subfolder/log.txt",name="log.txt")
  29. attachmentObject2 <- mime_part(x="subfolder/log2.txt",name="log2.txt")
  30. bodyWithAttachment <- list(body,attachmentObject,attachmentObject2)
  31.  
  32. sudo apt-get install openjdk-jdk
  33.  
  34. install.packages("devtools", dep = T)
  35. library(devtools)
  36. install_github("rpremraj/mailR")
  37.  
  38. library(mailR)
  39. send.mail(from = "[email protected]",
  40. subject = "Subject of the email",
  41. body = "Body of the email",
  42. smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = TRUE),
  43. authenticate = TRUE,
  44. send = TRUE,
  45. attach.files = c("./download.log", "upload.log", "https://dl.dropboxusercontent.com/u/5031586/How%20to%20use%20the%20Public%20folder.rtf"),
  46. file.names = c("Download log.log", "Upload log.log", "DropBox File.rtf"), # optional parameter
  47. file.descriptions = c("Description for download log", "Description for upload log", "DropBox File"), # optional parameter
  48. debug = TRUE)
  49.  
  50. SendMail <- function(from="[email protected]",to="[email protected]",text="Hallo",subject="Sag Hallo",smtp="smtp.my.server.de",user="me.myself.and.i",pw="123"){
  51. require(stringr)
  52. part1 <- "Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
  53. Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
  54. Const cdoAnonymous = 0 'Do not authenticate
  55. Const cdoBasic = 1 'basic (clear-text) authentication
  56. Const cdoNTLM = 2 'NTLM "
  57.  
  58. part2 <- paste(paste("Set objMessage = CreateObject(",'"',"CDO.Message",'"',")" ,sep=""),
  59. paste("objMessage.Subject = ",'"',subject,'"',sep=""),
  60. paste("objMessage.From = ",'"',from,'"',sep=""),
  61. paste("objMessage.To = ",'"',to,'"',sep=""),
  62. paste("objMessage.TextBody = ",'"',text,'"',sep=""),
  63. sep="n")
  64.  
  65. part3 <- paste(
  66. "'==This section provides the configuration information for the remote SMTP server.
  67.  
  68. objMessage.Configuration.Fields.Item _
  69. ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  70.  
  71. 'Name or IP of Remote SMTP Server
  72. objMessage.Configuration.Fields.Item _
  73. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ",'"',smtp,'"',"
  74.  
  75. 'Type of authentication, NONE, Basic (Base64 encoded), NTLM
  76. objMessage.Configuration.Fields.Item _
  77. ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
  78.  
  79. 'Your UserID on the SMTP server
  80. objMessage.Configuration.Fields.Item _
  81. ("http://schemas.microsoft.com/cdo/configuration/sendusername") = ",'"',user,'"',"
  82.  
  83. 'Your password on the SMTP server
  84. objMessage.Configuration.Fields.Item _
  85. ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ",'"',pw,'"', "
  86.  
  87. 'Server port (typically 25)
  88. objMessage.Configuration.Fields.Item _
  89. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  90.  
  91. 'Use SSL for the connection (False or True)
  92. objMessage.Configuration.Fields.Item _
  93. ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
  94.  
  95. 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
  96. objMessage.Configuration.Fields.Item _
  97. ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  98. objMessage.Configuration.Fields.Update
  99.  
  100. '==End remote SMTP server configuration section==
  101.  
  102. objMessage.Send
  103. ",sep="")
  104.  
  105. vbsscript <- paste(part1,part2,part3,sep="nnn")
  106. str_split(vbsscript,"n")
  107. writeLines(vbsscript, "sendmail.vbs")
  108. shell("sendmail.vbs")
  109. unlink("sendmail.vbs")
  110. }
  111.  
  112. library(jsonlite)
  113. library(XML)
  114. library(httr)
  115. library(rjson)
  116. library(RCurl)
  117. options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
  118.  
  119. authenticate_twilio <- "https://[ACCOUNT SID]:[AUTH TOKEN]@api.twilio.com/2010-04-01/Accounts"
  120. authenticate_response <- getURL(authenticate_twilio)
  121. print(authenticate_response)
  122.  
  123. postForm("https://[ACCOUNT SID]:[AUTH TOKEN]@api.twilio.com/2010-04-01/Accounts/[ACCOUNT SID]/Messages.XML",.params = c(From = "+1[twilio phone#]", To = "+1[self phone#]",Body = "Hello from twilio"))
Add Comment
Please, Sign In to add comment