2016. 1. 19. 13:28

소스코드 : http://choi4547.tistory.com/entry/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EB%B3%84-%EA%B5%AC%EA%B8%80smtp-%EB%B0%9C%EC%86%A1


1. gmail


2단계 인증 : 사용중지로 되어 있어야 한다(2단계인증이 있을경우 "서버에 연결하지 못했습니다" 라는 오류메시지가 나타남)





2. naver








Posted by 팔개
2016. 1. 19. 01:08

출처 : 외국사이트인데, 기억이 --;;


naver 또는 google 사이트 계정설정 확인하기


1. ASP


<%@LANGUAGE="VBSCRIPT"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<%
   Set iMsg = CreateObject("CDO.Message")
   Set iConf = CreateObject("CDO.Configuration")
   Set Flds = iConf.Fields
   Flds.Item(schema & "sendusing") = 2
   Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
   Flds.Item(schema & "smtpserverport") = 587
   Flds.Item(schema & "smtpauthenticate") = 1
   Flds.Item(schema & "sendusername") = "demouser@gmail.com"
   Flds.Item(schema & "sendpassword") =  "*******"
   Flds.Item(schema & "smtpusessl") = 1
   Flds.Update
 
  With iMsg
  .To = "test@test.com"
  .From = "demouser@gmail.com"
  .Subject = "Test send with gmail account"
  .HTMLBody ="this is test email from gmail smtp"
  .Sender = "demouser"
  Set .Configuration = iConf
  SendEmailGmail = .Send
   End With
   set iMsg = nothing
   set iConf = nothing
   set Flds = nothing
   Response.Write "sent successfully"
%>
</body>
</html>



2. ASP.NET - C#


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@import namespace="System.Net"%>
<%@import namespace="System.Net.Mail"%>
<script language="C#" runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        MailMessage m = new MailMessage();
        SmtpClient sc = new SmtpClient();
         try
            {
                m.From = new MailAddress("demouser@gmail.com");                
                       m.To.Add("test@test.com");
                m.Subject = "This is a Test Mail";
                m.IsBodyHtml = true;
                m.Body = "test gmail";
                sc.Host = "smtp.gmail.com";
                sc.Port = 587;
                sc.Credentials = new System.Net.NetworkCredential("demouser@gmail.com","******");
                       
                sc.EnableSsl = true;
                sc.Send(m);
                Response.Write("Email Send successfully");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
    }
</script>
<html>
<body>
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
</body>
</html>



3. ASP.NET - VB.NET


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net.Mail" %>
<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
  
        Dim strFrom = "demouser@gmail.com" 
        Dim strTo = "test@test.com"
        Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))
        MailMsg.BodyEncoding = Encoding.Default
        MailMsg.Subject = "This is a test"
        MailMsg.Body = "This is a sample message using SMTP authentication"
        MailMsg.Priority = MailPriority.High
        MailMsg.IsBodyHtml = True
  
        Dim SmtpMail As New SmtpClient
        Dim basicAuthenticationInfo
        SmtpMail.Host = "smtp.gmail.com"
        SmtpMail.Port=587
        SmtpMail.DeliveryMethod = SmtpDeliveryMethod.Network
        SmtpMail.UseDefaultCredentials = False
        SmtpMail.Credentials = new System.Net.NetworkCredential("demouser@gmail.com","*******")
        SmtpMail.EnableSsl = true
        SmtpMail.Send(MailMsg)
        lblMessage.Text = "Mail Sent"    
    End Sub
</script>
<html>
<body>
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
</body>
</html>



4. PHP


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<?php
include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php"
 
$mail new PHPMailer();
 
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "demouser@gmail.com";
$mail->Password = "********";
 
$mail->From = "demouser@gmail.com";
$mail->FromName = "demouser";
 
$mail->AddAddress("test@test.com","test");
$mail->Subject = "This is the subject";
$mail->Body = "This is the body";
$mail->WordWrap = 50;
$mail->IsHTML(true);
 
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
</body>
</html>




Posted by 팔개
2016. 1. 7. 15:32

빨간색 글자를 추가 한다.

웹에서는 세션에 따라 ARITHABORT 가 OFF로 처리되는 경우가 발생한다고 함.

정확한 원인은 확인중..


Conn.Execute "SET ARITHABORT ON"

 

Set Cmd = Server.CreateObject("ADODB.Command")

With Cmd

       .ActiveConnection   =      Conn

       .CommandText        =      "ProcName"

       .CommandType        =      adCmdStoredProc

 

       .Parameters.Append .CreateParameter("@DPart", adChar, adParamInPut, 2, DPart)

       .Parameters.Append .CreateParameter("@YY", adChar, adParamInPut, 4, YY)

       .Parameters.Append .CreateParameter("@txtName", adVarChar, adParamInPut, 50, txtName)

 

       Set Rs = .Execute

       If Not Rs.Eof Then

             Dim Record : Record = Rs.GetRows()

       End If

       Rs.Close : Set Rs = Nothing

End With

Set Cmd = Nothing

 

Posted by 팔개