Guest User

Untitled

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