본문으로 건너뛰기

CDO 객체를 이용한 메일발송 ASP 예제가 어떻게 되나요?

💡 요약 정리

  • 카페24 윈도우 호스팅은 서버 자체 SMTP를 제공하지 않습니다.
  • CDO 객체로 카페24 메일서버에 연결해 SMTP 인증 후 발송해야 합니다.
  • 메일서버 예: mw-001.cafe24.com, mw-002.cafe24.com
  • 리셀러는 SMTP 서버를 mail-001.리셀러도메인으로 설정합니다.
  • 아래에 기본 발송/첨부파일 포함 ASP 예제를 제공합니다.

1. 사용 전 확인사항

  • 카페24 윈도우 호스팅 서버는 SMTP를 직접 제공하지 않습니다. 따라서 외부 메일서버(카페24 메일서버)에 연동해 발송하도록 소스가 구성되어 있습니다.
    • 메일서버 예시: mw-001.cafe24.com 또는 mw-002.cafe24.com
  • 일반적인 CDO 메일 발송과 다른 점은 SMTP 인증 설정이 포함된다는 것입니다.
    • 참고: CDONTS 객체는 원격 접속과 SMTP 인증 기능이 없어, 반드시 CDO로 구현해야 합니다.
  • 리셀러인 경우 SMTP 서버 설정을 다음과 같이 변경하세요.
    • .Item(cdoSMTPServer) = "mail-001.리셀러도메인"

2. CDO 객체를 이용한 메일발송 ASP 예제

아래 예제는 CDO를 사용해 SMTP 인증 후 메일을 발송하는 기본 예제입니다. 예제의 “메일서버주소”, “POP메일아이디@POP메일도메인”, “POP메일비밀번호”를 실제 환경에 맞게 바꿔주세요.

<%
Const cdoSendUsingMethod = _
"http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = _
"http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = _
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = _
"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAccountName = _
"http://schemas.microsoft.com/cdo/configuration/smtpaccountname"
Const cdoSMTPAuthenticate = _
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = _
"http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = _
"http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "메일서버주소"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "POP메일아이디@POP메일도메인"
.Item(cdoSendPassword) = "POP메일비밀번호"

.Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
.To = "batman@gotham.com"
.From = "superman@crypton.net"
.Subject = "Hello, this is test mail"
.HTMLBody = "Hello"
.Send
End With

Response.Write "Success"

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>

3. CDO 객체를 이용한 메일발송 ASP 예제 - 첨부파일 기능 포함

DEXTupload Pro를 사용한 예제입니다. 사용 중인 업로드 컴포넌트에 맞게 코드를 수정하세요. 업로드 저장 폴더에는 쓰기 권한을 부여해야 합니다.

<%
Set Uploadform = Server.CreateObject("DEXT.FileUpload")
Uploadform.DefaultPath = Server.MapPath("/업로드저장폴더명") '또는 절대경로(폴더에 쓰기권한 설정 필요)
AttachFile = Uploadform("attachfile").FileName


Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAccountName = "http://schemas.microsoft.com/cdo/configuration/smtpaccountname"
Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
Const cdoSendUsingPickup = "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"


Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields ' Get a handle on the config object and it's fields


Set objConfig = Server.CreateObject("CDO.Configuration")

Set Fields = objConfig.Fields ' Set config fields we care about


With Fields
  .Item(cdoSendUsingMethod) = cdoSendUsingPort
  .Item(cdoSMTPServer) = "메일서버주소"
  .Item(cdoSMTPServerPort) = 25
  .Item(cdoSMTPAuthenticate) = cdoBasic
  .Item(cdoSendUserName) = "POP메일아이디@POP메일도메인"
  .Item(cdoSendPassword) = "POP메일비밀번호"
  .Item(cdoSendUsingPickup) = Uploadform.DefaultPath

.Update
End With


Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig


With objMessage
.To = "batman@gotham.com"
.From = "superman@crypton.net"
.Subject = "Hello, this is test mail"
.HTMLBody = "Hello"
If AttachFile <> "" Then
  .AddAttachment Uploadform.DefaultPath & "/" & AttachFile
End If
.Send
End With


Response.Write "Success"


Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>
  • 참고: DEXTupload Pro를 예로 들었습니다. 사용하시는 Upload Component에 맞게 코드를 수정하세요.

4. POP 메일 계정 및 메일서버 주소 확인 방법

  • POP 메일 계정은 나의 서비스 관리 > 호스팅 관리 > 이메일계정 추가/삭제에서 생성할 수 있습니다.
  • 메일서버 주소(POP3/SMTP)는 위 “이메일계정 추가/삭제” 페이지에서 확인할 수 있습니다.
  • 서비스에 따라 메일서버 주소가 다를 수 있으니, 반드시 본인 서비스 페이지에서 직접 확인하세요.
이메일계정 추가/삭제 화면에서 메일서버 주소 확인 방법
  • 이메일 계정 관리 화면에서 POP3/SMTP 서버 주소 위치를 확인할 수 있습니다.