Hy
I am trying to send email using MS Outlook 15.0 object library and using VBA codes from host Excel 2013.
When the macro try to create MailItem, the Microsoft demand me to open OutLook 2013 account. Detail: my machine is running Outlook Web.
I ask if this demand is realy necessary.
Is there any solution to this problem?
2
I use this code, which uses powershell in the end.
Sub mailversand(tovar As String, betreff As String, mailbody As String, bccmax As Boolean, Optional attachm As String)
On Error GoTo ende
Dim fehlerzeile As Integer
Dim fileToSend As String, fromvar As String, server As String, commandzeile As String, anrede_re As String, port As String
fileToSend = "\myservertempmail_auftragseingang.html"
If (Dir(fileToSend) <> "") Then Kill fileToSend
Call textdatei_erstellen(fileToSend, mailbody)
fromvar = "[email protected] "
server = "vpn.domain.at"
port = 25
betreff = "'" & betreff & "'"
commandzeile = "send-mailmessage -From " & fromvar & " -Encoding ([System.Text.Encoding]::UTF8) -To " & tovar & " -Subject " & betreff & _
" -SmtpServer " & server & " -Port " & port
If attachm <> "" Then commandzeile = commandzeile & " -Attachments '" & attachm & "'"
If mailbody <> "" Then commandzeile = commandzeile & " -body (get-content -path " & fileToSend & ") -BodyAsHtml"
If bccmax = True Then commandzeile = commandzeile & " -BCC [email protected]"
commandzeile = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command " & Chr$(34) & commandzeile & Chr$(34)
Debug.Print commandzeile
Shell commandzeile, vbHide ' Use vbNormalFocus to show the PowerShell console
ende:
If Err <> 0 Then MsgBox("Err-Nr: " & Err.Number & Chr(10) & "Err-Desc: " & Err.Description & Chr(10) & "Err-Source: " & Err.Source & Chr(10) & "Sub Mailversand" & Chr(10) & Now())
End Sub
Function textdatei_erstellen(strPath, textzeile)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(Replace(strPath, "/", "-"))
oFile.WriteLine textzeile
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Function
I call that sub with
Sub test_mv()
Call mailversand("[email protected]", "test text", "supi dubi lsdfj sldkfj säö üsdfü äääüüüßßß #aá è ", False)
End Sub
you might want to change the error-handling. But this is far easier then using outlook, and there is no way to use outlook-web with VBA as far as I know.
Max