Copies de seguretat per correu (OpenOffice.org)

Aquesta és una macro per a l’OpenOffice.org per a enviar documents per correu electrònic de manera “silenciosa”.


Sub SendMailBackup()
Dim MailAddress As String, MessageSubject As String
Dim ThisDocURL As String, DocDir As String, FileName As String
Dim MailAgent As Object, MailClient As Object, MailMessage As Object, ThisDoc As Object
Dim Args()
ThisDoc=ThisComponent
If ThisDoc.hasLocation=False Then
MsgBox "You must save the document first!" :End
End If
ThisDocURL=ThisDoc.getURL()
If ThisDoc.isModified Then
ThisDoc.storeAsURL(ThisDocURL, Args)
End if
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
GlobalScope.BasicLibraries.LoadLibrary("Tools")
End If
DocDir=DirectoryNameoutofPath(ThisDocURL, GetPathSeparator())
FileName=Dir(ThisDocURL, 0)
MailAddress="backup@email.com"
MessageSubject="[OOO_DOC_BACKUP] " & FileName & " " & CDateToISO(Date) & " - " &_
Hour(Time)& ":" & Minute(Time) & ":" & Second(Time)
If GetGUIType=1 Then
MailAgent=CreateUnoService("com.sun.star.system.SimpleSystemMail")
Else
MailAgent=CreateUnoService("com.sun.star.system.SimpleCommandMail")
End If
MailClient=MailAgent.querySimpleMailClient()
MailMessage=MailClient.createSimpleMailMessage()
MailMessage.setRecipient(MailAddress)
MailMessage.setSubject(MessageSubject)
MailMessage.setAttachement(Array(ThisDocURL))
MailClient.sendSimpleMailMessage(MailMessage, 1)
End Sub

Font: Linux.com – OooBasic crash course: One-click email backup of OpenOffice.org documents