如何在R中发送格式良好的邮件

如何在R中发送格式良好的邮件,r,R,我使用下面提到的代码发送邮件,我可以更改粘贴在邮件正文上的表格格式吗?我想在邮件正文中发送格式良好/压缩的表格 第一个6是我的data.frame Date=sys.Date()-1 date2 <- paste("My subject of mail", Date, sep = " - ") setwd("/xyz") newdir <- paste("output", Sys.time(), sep = "_") dir.create(newdir)#, showWarnings

我使用下面提到的代码发送邮件,我可以更改粘贴在邮件正文上的表格格式吗?我想在邮件正文中发送格式良好/压缩的表格

第一个6是我的data.frame

Date=sys.Date()-1
date2 <- paste("My subject of mail", Date, sep = " - ")
setwd("/xyz")
newdir <- paste("output", Sys.time(), sep = "_")
dir.create(newdir)#, showWarnings = FALSE)
setwd(newdir)

######
mydoc = bsdoc( title = 'my document')
options( "ReporteRs-fontsize" = 8 )
mydoc = addParagraph(mydoc, value = "Hi All, \n\nPlease check attached summary.")
mydoc = addParagraph(mydoc, value = "Summary:")
MyFTable = FlexTable( data = first6, add.rownames = FALSE, header.cell.props = cellProperties( background.color = "#FAEBD7" )
                      , header.par.props = parProperties(text.align = "center" ))
MyFTable = setColumnsColors( MyFTable, j=1, colors = '#F0F8FF' )
MyFTable[ , ] = parProperties( text.align = 'center')
MyFTable = setColumnsColors( MyFTable, j=ncol(first6), colors = '#F0F8FF' )
mydoc = addFlexTable( mydoc, MyFTable )
writeDoc( mydoc, file = "op2.html" )

send.mail(from = "abc@xyz.com",
          to = c("abc@xyz.com"),
          subject = date2,
          body = "op2.html",
          html = TRUE,
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "abc@xyz.com", passwd = "xyz@123", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)
Date=sys.Date()-1

date2如果这不能回答您的问题,很抱歉,但我认为您需要使用正确的工具来完成正确的工作

In column A : Names of the people
In column B : E-mail addresses
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files)

The Macro will loop through each row in "Sheet1" and if there is a E-mail address in column B
and file name(s) in column C:Z it will create a mail with this information and send it.

Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    Dim OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim cell As Range
    Dim FileCell As Range
    Dim rng As Range

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set sh = Sheets("Sheet1")

    Set OutApp = CreateObject("Outlook.Application")

    For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)

        'Enter the path/file names in the C:Z column in each row
        Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")

        If cell.Value Like "?*@?*.?*" And _
           Application.WorksheetFunction.CountA(rng) > 0 Then
            Set OutMail = OutApp.CreateItem(0)

            With OutMail
                .to = cell.Value
                .Subject = "Testfile"
                .Body = "Hi " & cell.Offset(0, -1).Value

                For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
                    If Trim(FileCell) <> "" Then
                        If Dir(FileCell.Value) <> "" Then
                            .Attachments.Add FileCell.Value
                        End If
                    End If
                Next FileCell

                .Send  'Or use .Display
            End With

            Set OutMail = Nothing
        End If
    Next cell

    Set OutApp = Nothing
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
第A列:人员姓名
在B列中:电子邮件地址
在C:Z列中:类似C:\Data\Book2.xls的文件名(不必是Excel文件)
宏将循环遍历“Sheet1”中的每一行,如果B列中有电子邮件地址
和C:Z列中的文件名。它将创建一封包含此信息的邮件并发送。
子发送_文件()
“在Excel 2000-2016中工作
“有关提示,请参阅:http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp作为对象
将邮件变暗为对象
将sh设置为工作表
暗淡单元格作为范围
将文件单元设置为范围
变暗rng As范围
应用
.EnableEvents=False
.ScreenUpdate=False
以
设置sh=图纸(“图纸1”)
Set-OutApp=CreateObject(“Outlook.Application”)
对于sh.Columns(“B”).Cells.SpecialCells(xlCellTypeConstants)中的每个单元格
'在每行的C:Z列中输入路径/文件名
设置rng=sh.Cells(cell.Row,1).范围(“C1:Z1”)
如果单元格值像“*@*。?*”和_
Application.WorksheetFunction.CountA(rng)>0则
Set-OutMail=OutApp.CreateItem(0)
发邮件
.to=单元格.Value
.Subject=“Testfile”
.Body=“Hi”&单元格偏移量(0,-1).Value
对于rng.SpecialCells中的每个文件单元(xlCellTypeConstants)
如果修剪(文件单元)”,则
如果Dir(FileCell.Value)“,则
.Attachments.Add FileCell.Value
如果结束
如果结束
下一个文件单元
.Send'或use.Display
以
发送邮件=无
如果结束
下一个细胞
设置应用程序=无
应用
.EnableEvents=True
.ScreenUpdate=True
以
端接头
您可以在下面的链接中找到其他选项


如果这不能回答您的问题,很抱歉,但我认为您需要使用正确的工具来完成正确的工作

In column A : Names of the people
In column B : E-mail addresses
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files)

The Macro will loop through each row in "Sheet1" and if there is a E-mail address in column B
and file name(s) in column C:Z it will create a mail with this information and send it.

Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    Dim OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim cell As Range
    Dim FileCell As Range
    Dim rng As Range

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set sh = Sheets("Sheet1")

    Set OutApp = CreateObject("Outlook.Application")

    For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)

        'Enter the path/file names in the C:Z column in each row
        Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")

        If cell.Value Like "?*@?*.?*" And _
           Application.WorksheetFunction.CountA(rng) > 0 Then
            Set OutMail = OutApp.CreateItem(0)

            With OutMail
                .to = cell.Value
                .Subject = "Testfile"
                .Body = "Hi " & cell.Offset(0, -1).Value

                For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
                    If Trim(FileCell) <> "" Then
                        If Dir(FileCell.Value) <> "" Then
                            .Attachments.Add FileCell.Value
                        End If
                    End If
                Next FileCell

                .Send  'Or use .Display
            End With

            Set OutMail = Nothing
        End If
    Next cell

    Set OutApp = Nothing
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
第A列:人员姓名
在B列中:电子邮件地址
在C:Z列中:类似C:\Data\Book2.xls的文件名(不必是Excel文件)
宏将循环遍历“Sheet1”中的每一行,如果B列中有电子邮件地址
和C:Z列中的文件名。它将创建一封包含此信息的邮件并发送。
子发送_文件()
“在Excel 2000-2016中工作
“有关提示,请参阅:http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp作为对象
将邮件变暗为对象
将sh设置为工作表
暗淡单元格作为范围
将文件单元设置为范围
变暗rng As范围
应用
.EnableEvents=False
.ScreenUpdate=False
以
设置sh=图纸(“图纸1”)
Set-OutApp=CreateObject(“Outlook.Application”)
对于sh.Columns(“B”).Cells.SpecialCells(xlCellTypeConstants)中的每个单元格
'在每行的C:Z列中输入路径/文件名
设置rng=sh.Cells(cell.Row,1).范围(“C1:Z1”)
如果单元格值像“*@*。?*”和_
Application.WorksheetFunction.CountA(rng)>0则
Set-OutMail=OutApp.CreateItem(0)
发邮件
.to=单元格.Value
.Subject=“Testfile”
.Body=“Hi”&单元格偏移量(0,-1).Value
对于rng.SpecialCells中的每个文件单元(xlCellTypeConstants)
如果修剪(文件单元)”,则
如果Dir(FileCell.Value)“,则
.Attachments.Add FileCell.Value
如果结束
如果结束
下一个文件单元
.Send'或use.Display
以
发送邮件=无
如果结束
下一个细胞
设置应用程序=无
应用
.EnableEvents=True
.ScreenUpdate=True
以
端接头
您可以在下面的链接中找到其他选项