16. 10. 24.

VB.NET Email 전송

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Function eMailCDOSend(MailTitle As String, MailTag As String, Sender As String, Receiver As String, addFile As String) As Boolean
    ' MailTitle : 제목
     ' MailTag : html내용
     ' Sender : 보내는 사람
     ' Receiver : 받는사람
 
    Dim eMailObject, eMailConfig
    Dim SchemaPath
 
    eMailObject = Server.CreateObject("CDO.Message")
    eMailConfig = Server.CreateObject("CDO.Configuration")
    Try
        With eMailConfig.Fields
            .Item(SchemaPath & "sendusing") = 2  'CDOSendUsingPort
            .Item(SchemaPath & "smtpserver") = "127.0.0.1"  'CDOSendUsingPort [ServerIP]
            .Item(SchemaPath & "smtpserverport") = "325"     'Port
            .Update
        End With
        eMailObject.Configuration = eMailConfig
 
        eMailConfig = Nothing
        If addFile <> "" Then
            eMailObject.To = Receiver
            eMailObject.From = Sender
            eMailObject.Subject = MailTitle
            eMailObject.HTMLBody = MailTag
            eMailObject.BodyPart.Charset = "ks_c_5601-1987"
            eMailObject.HTMLBodyPart.Charset = "ks_c_5601-1987"
            eMailObject.HTMLBodyPart.ContentTransferEncoding = "quoted-printable"
            eMailObject.AddAttachment(addFile)
            eMailObject.fields.update
            eMailObject.Send
        Else
            With eMailObject
                .From = Sender
                .To = Receiver
                .Subject = MailTitle
                .HTMLBody = MailTag
                .BodyPart.Charset = "ks_c_5601-1987"
                .HTMLBodyPart.Charset = "ks_c_5601-1987"
                .HTMLBodyPart.ContentTransferEncoding = "quoted-printable"
                .Send
            End With
       End If
        eMailObject = Nothing
    Catch ex As Exception
        Return False
    End Try
    Return True
End Function

댓글 없음:

댓글 쓰기