AW: Datei per Mail versenden
04.11.2013 11:40:56
Tino
Hallo,
also habe es gerade nocheinmal getestet auch auf ein GMAIL Konto, geht bei mir.
Hast Du bei dir den Serverport richtig angegeben in der Regel 465 (bei mir) evtl. auch 587.
Ich kann die Mail nicht aus der geöffneten Datei senden
Dann speichere eine kopie dieser Datei und sende diese.
Wenn es große Dateien sind, evtl. auch mal mit einen Timeout testen.
Hier ein Beispiel
Sub EMail__Senden_Ohne_Outlook()
Dim iNachricht As Object, iKonfiguration As Object, Felder As Variant
Dim strMailAdress$, strKennwort$, strTmpFile$
strMailAdress = "xxxxxx@gmail.com" '"Deine E-Mail-Adresse"
strKennwort = "xxxxxxxxx" 'Passwort angeben
'Datei für Anlage erstellen
strTmpFile = ThisWorkbook.Path
If Right$(strTmpFile, 1) <> "\" Then strTmpFile = strTmpFile & "\"
ChDrive strTmpFile
ChDir strTmpFile
'File Name für Nachricht
strTmpFile = strTmpFile & "Mail_" & ThisWorkbook.Name
'evtl. löschen fals vorhanden
If Dir(strTmpFile, vbNormal) <> "" Then Kill strTmpFile
'eine kopie der Datei speichern
ThisWorkbook.SaveCopyAs strTmpFile
Set iNachricht = CreateObject("CDO.Message")
Set iKonfiguration = CreateObject("CDO.Configuration")
iKonfiguration.Load -1
Set Felder = iKonfiguration.Fields
With Felder
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strMailAdress
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strKennwort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 'Postausgangsserver
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'SMTP-Port
.Item("http://schemas.microsoft.com/cdo/configuration/smtpservertimeout") = 60 'Timeout
.Update
End With
With iNachricht
Set .Configuration = iKonfiguration
.To = "xxxxxx@Proviter.com" 'Empfänger
.CC = "" 'Zur Kenntnis
.BCC = "" '.BCC nicht sichtbare Empfänger
.Sender = strMailAdress 'Von
.Subject = "Betreff" 'Betreffzeile
.TextBody = "Deine Nachricht!" 'Nachricht
.AddAttachment strTmpFile 'Anlage
.Send
End With
'Datei wieder löschen
If Dir(strTmpFile, vbNormal) <> "" Then Kill strTmpFile
End Sub
Gruß Tino