Quick Start : SMTP | Minicoder


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";

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章