Hallo Reinhard
Leerer Anhang heißt Es wir ein Anhang angezeigt der ist aber 0 Byte lang.
Den Code habe ich selbst geschrieben.
Das bezweifle ich leider sehr, da ich den Code 1 zu 1 mehrmals im Netz gefunden habe:
z.b. hier :http://permalink.gmane.org/gmane.comp.documentfoundation.discuss/6416
Insbesondere was die Verwendung
des Outputstream betrifft bin ich mir absolut nicht sicher ob es sich
dabei um einen richtigen Ansatz handelt. Ich bin nur darauf gekommen
weil in der Doc zu "Dataflavor" für "datatype" "XOutputStream" als
Beispiel angeführt wird.
Deine Variable oOutputStream müsste mit deiner Methode ein String enthalten,
der den gesamten Inhalt der pdf Datei enthält. Das tut sie aber nicht.
Eine Möglichkeit, um das zu realisieren wäre, dass du
1. die pdf-Datei speicherst
2. zum lesen als *.*.txt öffnest
3. den text als stringvariable speicherst.
und dann alles wie gehabt.
Das funktioniert leider auch nicht, da nur Asci2 unterstützt wird, und die pdf datei als String ungefähr so ausschaut:
"oÏHH%µ[î½.Xsöòà‚Õ'›ŒŒaIÑÏi…ø28É…xó¥+Œaé
P"......
Hier trotzdem der Code, damit du weist, was ich meine.
Wenn du ein paar Kleinigkeiten abänderst, dann bekommst du einen einwandfreien Anhang, allerdings nur als CSV oder txt Datei
hinter der 3. Zeile mit "=========" der andere Code.
Eine einfache methode ist: simplemailmessage sihe:
http://api.openoffice.org/docs/common/ref/com/sun/star/system/XSimpleMailMessage.html
allerdings kannst du da kein "Boody" setzen.
Eine methode, mit der du auch einen "Boody" Versenden kannst ist:
shell("C:\thunderbird\thunderbird.exe", 3, "-Compose to=" & sEmail & ",subject=" & sBetreff & ",body=" & sText & ",attachment=" & sDatei)
der nachteil hier ist, dass du jedesmahl bei Tunderbird noch auf Absenden klicken mußt.
gruß frieder
'==========================================================================================================
'So müßte dein code aussehen, aber es geht leider nicht.
Global oOutputStream as Object
Global sDir as string
Sub Mailtest
Dim Attachment(1) as Object
Dim aAttach(0) as string
GlobalScope.BasicLibraries.LoadLibrary( "Tools" )
Doc = ThisComponent
sUrl = ThisComponent.getURL()
Path = DirectoryNameoutofPath(sUrl, "/")
Pfad1 = ConvertFromUrl(Path)
sDir = Pfad1 & GetPathSeparator & "Test1.pdf"
sDir1 = converttourl(sDir)
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ExportFormFields" 'just show the contents of the Form.Fields
args1(0).Value= True
args1(1).Name = "Printing" ' you don't need that.
args1(1).Value= 0
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FilterName"
args2(0).Value = "writer_pdf_Export"
args2(1).Name = "FilterData"
args2(1).Value = args1
ThisComponent.storeToURL(sDir1,args2())
oMailProvider = CreateUNOService("com.sun.star.mail.MailServiceProvider")
oCont = CreateUNOListener("CurCont_","com.sun.star.uno.XCurrentContext")
oAuth = CreateUNOListener("Authent_","com.sun.star.mail.XAuthenticator")
oTrans= CreateUNOListener("Trans_","com.sun.star.datatransfer.XTransferable")
oAtt = CreateUNOListener("Att_","com.sun.star.datatransfer.XTransferable")
Attachment=CreateObject("com.sun.star.mail.MailAttachment")
Attachment.data=oAtt
Attachment.ReadableName="Testattachment.pdf"
oMailServiceObj = com.sun.star.mail.MailMessage
oMail = oMailServiceObj.createwithattachment _
( "to@beispiel.de", "from@beispiel.de","the subject", oTrans, Attachment)
xMailServer = oMailProvider.create("com.sun.star.mail.SMTP")
xMailServer.Connect(oCont,oAuth)
xMailServer.SendMailMessage(oMail)
xMailServer.Disconnect()
End Sub
Function Trans_getTransferData(f) As Any
if f.MimeType = "text/html" then
Trans_getTransferData = "<html><body><p>My Mail!</p></body></html>"
end if
End Function
Function Trans_getTransferDataFlavors() As Variant
Dim f As New com.sun.star.datatransfer.DataFlavor
f.MimeType = "text/html"
Trans_getTransferDataFlavors = Array(f)
End Function
Function Trans_isDataFlavorSupported(f) As Boolean
Trans_isDataFlavorSupported = (f.MimeType = "text/html")
End Function
Function Att_getTransferData(f) As Any
if f.MimeType = "application/pdf" then
iNumber = Freefile
Open sDir For Input As #iNumber
While not eof(iNumber)
Line Input #iNumber, sZeile
If sZeile <>"" then
sMsg = sMsg & sZeile & chr(10)
end if
wend
Close #iNumber
Att_getTransferData = sMsg
end if
End Function
Function Att_getTransferDataFlavors() As Variant
Dim f As New com.sun.star.datatransfer.DataFlavor
f.MimeType = "application/pdf"
f.HumanPresentableName="PDF-Datei"
Att_getTransferDataFlavors = Array(f)
End Function
Function Att_isDataFlavorSupported(f) As Boolean
Att_isDataFlavorSupported = (f.MimeType = "application/pdf")
End Function
Function CurCont_GetValueByName(s) as Any
Select Case s
Case "ServerName"
CurCont_GetValueByName = "smtp.beispiel.de"
Case "Port"
CurCont_GetValueByName = 25
Case "ConnectionType"
CurCont_GetValueByName = "Insecure"
End Select
End Function
Function Authent_GetUserName() as Any
Authent_GetUserName = "your_name@beispiel.de"
End Function
Function Authent_GetPassword()
Authent_GetPassword = "your_Passwort"
End Function
'=====================================================================
'dieser code funktioniert, aber du kannst nur txt oder csv dateien erzeugen, und du darfst keine sonderzeichen verwenden.
Global oOutputStream as Object
Global sDir as string
Sub Mailtest
Dim Attachment(1) as Object
Dim aAttach(0) as string
GlobalScope.BasicLibraries.LoadLibrary( "Tools" )
Doc = ThisComponent
sUrl = ThisComponent.getURL()
Path = DirectoryNameoutofPath(sUrl, "/")
Pfad1 = ConvertFromUrl(Path)
sDir = Pfad1 & GetPathSeparator & "Test1.pdf"
sDir1 = converttourl(sDir)
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ExportFormFields" 'just show the contents of the Form.Fields
args1(0).Value= True
args1(1).Name = "Printing" ' you don't need that.
args1(1).Value= 0
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FilterName"
args2(0).Value = "writer_pdf_Export"
args2(1).Name = "FilterData"
args2(1).Value = args1
ThisComponent.storeToURL(sDir1,args2())
oMailProvider = CreateUNOService("com.sun.star.mail.MailServiceProvider")
oCont = CreateUNOListener("CurCont_","com.sun.star.uno.XCurrentContext")
oAuth = CreateUNOListener("Authent_","com.sun.star.mail.XAuthenticator")
oTrans= CreateUNOListener("Trans_","com.sun.star.datatransfer.XTransferable")
oAtt = CreateUNOListener("Att_","com.sun.star.datatransfer.XTransferable")
Attachment=CreateObject("com.sun.star.mail.MailAttachment")
Attachment.data=oAtt
Attachment.ReadableName="Testattachment.txt"
oMailServiceObj = com.sun.star.mail.MailMessage
oMail = oMailServiceObj.createwithattachment _
( "to@beispiel.de", "from@beispiel.de","the subject", oTrans, Attachment)
xMailServer = oMailProvider.create("com.sun.star.mail.SMTP")
xMailServer.Connect(oCont,oAuth)
xMailServer.SendMailMessage(oMail)
xMailServer.Disconnect()
End Sub
Function Trans_getTransferData(f) As Any
if f.MimeType = "text/html" then
Trans_getTransferData = "<html><body><p>My Mail!</p></body></html>"
end if
End Function
Function Trans_getTransferDataFlavors() As Variant
Dim f As New com.sun.star.datatransfer.DataFlavor
f.MimeType = "text/html"
Trans_getTransferDataFlavors = Array(f)
End Function
Function Trans_isDataFlavorSupported(f) As Boolean
Trans_isDataFlavorSupported = (f.MimeType = "text/html")
End Function
Function Att_getTransferData(f) As Any
if f.MimeType = "application/pdf" then
Att_getTransferData = "Hallo das ist ein Beispiel" & Chr(10) & _
"sdfsdfdfgsdfgdfgjghkzuikjm" & Chr(10) & _
"Gruß Frieder"
end if
End Function
Function Att_getTransferDataFlavors() As Variant
Dim f As New com.sun.star.datatransfer.DataFlavor
f.MimeType = "application/pdf"
f.HumanPresentableName="PDF-Datei"
Att_getTransferDataFlavors = Array(f)
End Function
Function Att_isDataFlavorSupported(f) As Boolean
Att_isDataFlavorSupported = (f.MimeType = "application/pdf")
End Function
Function CurCont_GetValueByName(s) as Any
Select Case s
Case "ServerName"
CurCont_GetValueByName = "smtp.beispiel.de"
Case "Port"
CurCont_GetValueByName = 25
Case "ConnectionType"
CurCont_GetValueByName = "Insecure"
End Select
End Function
Function Authent_GetUserName() as Any
Authent_GetUserName = "your_name@beispiel.de"
End Function
Function Authent_GetPassword()
Authent_GetPassword = "your_Passwort"
End Function