Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(sendmailR)
- #set working directory
- setwd("C:/workingdirectorypath")
- #####send plain email
- from <- "you@account.com"
- to <- "recipient@account.com"
- subject <- "Email Subject"
- body <- "Email body."
- mailControl=list(smtpServer="serverinfo")
- sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)
- #####send same email with attachment
- #needs full path if not in working directory
- attachmentPath <- "subfolder/log.txt"
- #same as attachmentPath if using working directory
- attachmentName <- "log.txt"
- #key part for attachments, put the body and the mime_part in a list for msg
- attachmentObject <- mime_part(x=attachmentPath,name=attachmentName)
- bodyWithAttachment <- list(body,attachmentObject)
- sendmail(from=from,to=to,subject=subject,msg=bodyWithAttachment,control=mailControl)
- attachmentObject <- mime_part(x="subfolder/log.txt",name="log.txt")
- attachmentObject2 <- mime_part(x="subfolder/log2.txt",name="log2.txt")
- bodyWithAttachment <- list(body,attachmentObject,attachmentObject2)
- sudo apt-get install openjdk-jdk
- install.packages("devtools", dep = T)
- library(devtools)
- install_github("rpremraj/mailR")
- library(mailR)
- send.mail(from = "sender@gmail.com",
- to = c("recipient1@gmail.com", "recipient2@gmail.com"),
- subject = "Subject of the email",
- body = "Body of the email",
- smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = TRUE),
- authenticate = TRUE,
- send = TRUE,
- attach.files = c("./download.log", "upload.log", "https://dl.dropboxusercontent.com/u/5031586/How%20to%20use%20the%20Public%20folder.rtf"),
- file.names = c("Download log.log", "Upload log.log", "DropBox File.rtf"), # optional parameter
- file.descriptions = c("Description for download log", "Description for upload log", "DropBox File"), # optional parameter
- debug = TRUE)
- 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"){
- require(stringr)
- part1 <- "Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
- Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
- Const cdoAnonymous = 0 'Do not authenticate
- Const cdoBasic = 1 'basic (clear-text) authentication
- Const cdoNTLM = 2 'NTLM "
- part2 <- paste(paste("Set objMessage = CreateObject(",'"',"CDO.Message",'"',")" ,sep=""),
- paste("objMessage.Subject = ",'"',subject,'"',sep=""),
- paste("objMessage.From = ",'"',from,'"',sep=""),
- paste("objMessage.To = ",'"',to,'"',sep=""),
- paste("objMessage.TextBody = ",'"',text,'"',sep=""),
- sep="n")
- part3 <- paste(
- "'==This section provides the configuration information for the remote SMTP server.
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
- 'Name or IP of Remote SMTP Server
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ",'"',smtp,'"',"
- 'Type of authentication, NONE, Basic (Base64 encoded), NTLM
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
- 'Your UserID on the SMTP server
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/sendusername") = ",'"',user,'"',"
- 'Your password on the SMTP server
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ",'"',pw,'"', "
- 'Server port (typically 25)
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
- 'Use SSL for the connection (False or True)
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
- 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
- objMessage.Configuration.Fields.Update
- '==End remote SMTP server configuration section==
- objMessage.Send
- ",sep="")
- vbsscript <- paste(part1,part2,part3,sep="nnn")
- str_split(vbsscript,"n")
- writeLines(vbsscript, "sendmail.vbs")
- shell("sendmail.vbs")
- unlink("sendmail.vbs")
- }
- library(jsonlite)
- library(XML)
- library(httr)
- library(rjson)
- library(RCurl)
- options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
- authenticate_twilio <- "https://[ACCOUNT SID]:[AUTH TOKEN]@api.twilio.com/2010-04-01/Accounts"
- authenticate_response <- getURL(authenticate_twilio)
- print(authenticate_response)
- 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