Mail per SMTP mit SSL/TLS

15. Januar 2009 16:37

Hallo,

neues Problem. :-)

Kann man aus Navision heraus Mails versenden (ja, ich weiß, das geht, aber ...), die über einen SMTP-Mailserver gehen, der nur SSL/TLS-Verbindungen zulässt? Mailserver ist Postfix.

Tux23

Re: Mail per SMTP mit SSL/TLS

15. Januar 2009 17:05

Hallo Tux23,

du hast aber auch immer Sonderwünsche. Ich glaube das wird so einfach nicht funktionieren.
evtl. kannst du mit der Komponente etwas mehr erreichen.
Evtl. (nur eine Idee) gibt es ja im Internet einen OCX, der SSL/TLS kann. Diese Komponente müsste dann in Codeunit 400 zum versenden der Mails benutzt werden.


Gruß, Fiddi

Re: Mail per SMTP mit SSL/TLS

15. Januar 2009 17:38

Wenn Du das unten noch ein bischen erweiterst und in ein COM-Projekt packst (.NET 2.0) solltest Du es per Automation einbinden können:

Code:
Imports System.Net.Mail
Imports System.Net.Mime

Public Class clsMail

    Function sendMail(ByVal from As String, ByVal mailto As String, ByVal mailsubject As String, ByVal mailbody As String, ByVal attachedfile As String) As String

        ' Set mailServerName to be the name of the mail server
        ' you wish to use to deliver this message
        Dim mailServerName As String = "192.168.100.1"

        Try
            ' MailMessage is used to represent the e-mail being sent
            Using message As New MailMessage(from, mailto, mailsubject, mailbody)

                Dim data As Attachment
                data = New Attachment(attachedfile, MediaTypeNames.Application.Octet)
                Dim disposition As ContentDisposition = data.ContentDisposition
                disposition.CreationDate = System.IO.File.GetCreationTime(attachedfile)
                disposition.ModificationDate = System.IO.File.GetLastWriteTime(attachedfile)
                disposition.ReadDate = System.IO.File.GetLastAccessTime(attachedfile)

                message.Attachments.Add(data)

                ' SmtpClient is used to send the e-mail
                Dim mailClient As New SmtpClient(mailServerName)
                ' UseDefaultCredentials tells the mail client to use the
                ' Windows credentials of the account (i.e. user account)
                ' being used to run the application
                mailClient.UseDefaultCredentials = True

                ' Send delivers the message to the mail server
                mailClient.Send(message)
            End Using
            Return "Message sent with Attachment."
        Catch ex As FormatException
            Return ex.Message
        Catch ex As SmtpException
            Return ex.Message
        End Try

    End Function

    Function sendMail(ByVal from As String, ByVal mailto As String, ByVal mailsubject As String, ByVal mailbody As String) As String

        ' Set mailServerName to be the name of the mail server
        ' you wish to use to deliver this message
        Dim mailServerName As String = "192.168.100.1"

        Try
            ' MailMessage is used to represent the e-mail being sent
            Using message As New MailMessage(from, mailto, mailsubject, mailbody)

                ' SmtpClient is used to send the e-mail
                Dim mailClient As New SmtpClient(mailServerName)
                ' UseDefaultCredentials tells the mail client to use the
                ' Windows credentials of the account (i.e. user account)
                ' being used to run the application
                mailClient.UseDefaultCredentials = True

                ' Send delivers the message to the mail server
                mailClient.Send(message)
            End Using
            Return "Message sent."
        Catch ex As FormatException
            Return ex.Message
        Catch ex As SmtpException
            Return ex.Message
        End Try

    End Function

End Class


Volker

Re: Mail per SMTP mit SSL/TLS

16. Januar 2009 09:35

Hallo Tux23,

evtl. kannst du den MAIL-Server auch austricksen, indem du einen SSL-Gateway mit z.B. Putty aufbaust, der die SSL-Verbindung herstellt.

Gruß, Fiddi