Imports System.Data

Imports System.Net.Mail

Imports System.IO

 

Public Class MailFunction

    Private PublicFun As New PublicFunction

    Private DatabaseFun As New Database

    ''' <summary>

    ''' E-Mail 發送程式

    ''' </summary>

    ''' <param name="sP_Title">信件標題</param>

    ''' <param name="sP_Content">信件內文</param>

    ''' <param name="sP_FilePath">附件路徑</param>

    ''' <param name="sP_MailTO">寄送清單</param>

    ''' <returns></returns>

    ''' <remarks></remarks>

    Public Function SendMail(ByVal sP_Title As String, ByVal sP_Content As String, ByVal sP_FilePath As String, Optional ByVal sP_MailTO As String = "") As String

        '使用CDONTS.NewMail 發送

        Dim obj_NewMail As CDONTS.NewMail = New CDONTS.NewMail

        Dim sL_FromMail As String = "xxxxx@xxxx.com"

        Dim sL_ToMail As String = ""

        Dim sL_CcMail As String = ""

        Dim sL_Date As String = Format(Now(), "yyyyMMdd")

 

        With obj_NewMail

            '寄件者

            .From = sL_FromMail

            '內文

            .Body = sP_Content

            '主旨

            .Subject = "主旨XXX"

            '收信人

            .To = sL_ToMail

            '副本

            .Cc = sL_CcMail

            If sP_FilePath <> "" Then

                .AttachFile(sP_FilePath)

            End If

            .MailFormat = CDONTS.CdoMailFormats.CdoMailFormatMime

            .BodyFormat = CDONTS.CdoBodyFormats.CdoBodyFormatHTML

        End With

        Try

            obj_NewMail.Send()

        Catch ex As Exception

            Return "Error"

        End Try

        Return "寄送完成"

    End Function

 

End Class

arrow
arrow
    全站熱搜

    M 發表在 痞客邦 留言(0) 人氣()