Quick Start : SMTP | Minicoder

本文详细介绍如何使用ASPEmail、CDO及PHPMailer等工具发送电子邮件,并探讨了本地主机认证的问题及SMTP认证的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Download Demo

I am not care about the theory , please give me a link to download the installer directly. Click here to get the minicoder, you will be able to double-click to send out emails from your local computer.

How to send email via ASPEmail?

function sendEmail()
    on error resume next
        Set objMail = CreateObject("Persits.MailSender")
        Mail.Host = ""
        Mail.From = ""
        Mail.AddAddress "" 
        Mail.Username = ""
        Mail.Password = ""

        Mail.Subject = ""
        Mail.Body = ""
        Mail.Send

        If Err.Number <> 0 Then
            sendEmail=  ""
        else
            sendEmail= ""
        end if 

        Set objMail = Nothing
    on error goto 0
end function

How to send email via CDO?

function sendMail()
    on error resume next
        set objMail = WScript.CreateObject("CDO.Message")
        with objMail 
            .subject = ""
            .from = ""
            .to = ""		
            .TextBody = ""
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = ""
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = ""
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "" 
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
            .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
            .Configuration.Fields.Update
            .Send
            if (err <> 0) then 
                sendMail = ""
            else 
                sendMail = ""
            end With
        set objMail = Nothing
    on error goto 0
end function

How to send email via PHPMailer?

<?php
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "";
    $mail->From=""; 
    $mail->SMTPAuth = true;
    $mail->Username = "";
    $mail->Password = "";
    $mail->AddAddress("");
    $mail->Subject = "";
    $mail->Body = "";
    if(!$mail->Send())
    {
       echo "";
    }
    else
    {
       echo "";
    }
?>

What is localhost authentication?

Most servers have smtp enabled by default using localhost. However, localhost smtp doesn't require smtp authentication at all. The original purpose is to simplify web form programming where you can send emails easily via script. But this leaves a problem, senders can abuse the service easily. For example they can use it for bulk mail purpose or spam! The direct effect is hosting server will be overloaded so any existing service will be slowed down. What worse is the entire server might be blacklisted by major ISPs and all other customers on the server will not be able to send mails any more. If you enabled local SMTP service, your code should be somthing like 

<?php
    $toEmailAddress = "";
    $body = "";
    $subject = "";

    mail($toEmailAddress, $subject, $body);
?> 

The code is simple , however, it has risk to send out spam, most hosting provider can not support the mail() function including the most famous wordpress website. The mail function of wordpress, for example the forget password function , are using mail() function by default. If the hosting provder can not support localhost smtp, you will be able to get an error with keyword localhost.

Why SMTP authentication?

SMTP authentication will solve the localhost SMTP problem perfectly. Via smtp authentication, you must specify the correct SMTP credentials in coding. In this way all your emails will be sent out via actual email servers where you have to follow various rules such as daily limits, spam filters etc. In a word, smtp authentication protected both web and mail servers and all clients will benefit from it. That's why localhost smtp is not allowed any more by more and more hosting providers. Alternatively, they will guide you to use smtp authentication. 

Troubleshooting

From address = SMTP authentication address

Most hosting provider requires from address same as SMTP authentication address , please check 

Sample code could not works after changed parameters

Please check if you have related email component installed on related servers first.

  • ASPEmail, you should download their official installer first, click here forwarding to download page.
  • CDO, please make sure your server support classic ASP language
  • PHPMailer, please make sure you have download phpmailer source code and include class.phpmailer.php file with correct file path in your project

Encoding issue

You will be able to set up encoding in your code , for example

$mail->CharSet ="utf-8";

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值