⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtp.htm

📁 实现smtp的发送邮件的功能
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html>

<head>
<title>CSMTPConnection v1.21</title>
</head>

<body bgcolor="#FFFFFF">

<p align="left"><img src="smtp.gif" width="39" height="38" alt="smtp.gif (295 bytes)"><font
face="Arial"><big><big><big><big><strong>CSMTPConnection v1.21</strong></big></big></big></big></font></p>

<p><font face="Arial">Welcome to <strong>CSMTPConnection</strong>, a freeware MFC class to
support the SMTP protocol. SMTP for those not familiar with all the internet protocols is
the protocol used to send internet email.</font></p>

<p><font face="Arial">For detailed information about the <strong>S</strong>imple <strong>M</strong>ail
<strong>T</strong>ransfer <strong>P</strong>rotocol you should read RFC 821, You can
download this from <a href="ftp://ds.internic.net/rfc/rfc821.txt">ftp://ds.internic.net/rfc/rfc821.txt</a>.
If this server is unavailable, try <a href="ftp://venera.isi.edu/in_notes/">ftp://venera.isi.edu/in_notes/</a></font></p>

<p><font face="Arial">Another document that these classes refer to is RFC 2045 which
defines how MIME attachments are to be handled in a standard SMTP message. You can
download this from <a href="ftp://ds.internic.net/rfc/rfc2045.txt">ftp://ds.internic.net/rfc/rfc2045.txt</a>.
Again, If this server is unavailable, try <a href="ftp://venera.isi.edu/in_notes/">ftp://venera.isi.edu/in_notes/</a>
</font></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<table>
  <tr>
    <td><font face="Arial"><a href="#Features">Features</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Usage">Usage</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#History">History</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#APIReference">API Reference</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Enhancements">Planned Enhancements</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Contact">Contacting the Author</a></font></td>
  </tr>
</table>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><a name="Features"></a><big><strong><big>Features</big></strong></big>
</font>

<ul>
  <li><font color="#000000" size="3" face="Arial">Simple and clean C++ interface.</font></li>
  <li><font color="#000000" size="3" face="Arial">The interface provided is synchronous which
    provides an easier programming model than using asynchronous sockets.</font></li>
  <li><font color="#000000" size="3" face="Arial">The code does not rely on the MFC socket
    classes. These classes have a number of shortcomings, one of which causes problems when
    they are used in NT services.</font></li>
  <li><font color="#000000" size="3" face="Arial">The code can be used in a console
    application without any problems (Again this is not the case for the MFC socket classes).</font></li>
  <li><font color="#000000" size="3" face="Arial">A configurable timeout for the connection
    can be set through the class API.</font></li>
  <li><font color="#000000" size="3" face="Arial">The classes are fully Unicode compliant and
    include Unicode built options in the workspace file.</font></li>
  <li><font color="#000000" size="3" face="Arial">As of v1.1, the classes now fully supports
    sending file attachments.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a name="Usage"></a><font face="Arial"><big><big><strong>Usage</strong></big></big></font>

<ul>
  <li><font color="#000000" size="3" face="Arial">To use the class in your code simply include
    smtp.cpp in your project and #include smtp.h in which ever of your modules needs to make
    calls to the class.</font></li>
  <li><font face="Arial">Your code will need to include MFC either statically or dynamically.</font></li>
  <li><font face="Arial">You will need to have a functioning winsock stack installed and
    correctly initialised prior to calling any functions in CSMTPConnection. Depending on your
    application, this will involve calling either WSAStartup or AfxSocketInit at startup of
    your application.</font></li>
  <li><font face="Arial">You will also need to have afxtempl.h ,winsock.h or afxsock.h and
    afxpriv.h in your precompiled header. The code will work just aswell in a GUI or console
    app. The code should also work in a multithreaded application, although it has not be
    explicitly tested in this scenario.</font></li>
  <li><font face="Arial">To see the class in action, have a look at the code in InitInstance
    in the module &quot;main.cpp&quot;.&nbsp; For example to send a message to the author
    about this class, the code would look something like this (ignoring error handling):</font></li>
</ul>

<p><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPConnection
smtp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtp.Connect(&quot;mail.someisp.com&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPMessage m;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
m.AddRecipient(CSMTPAddress(&quot;pjn@indigo.ie&quot;));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.m_From =
CSMTPAddress(&quot;adeveloper@someisp.com&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.m_sSubject = &quot;A Fellow developer!&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.AddBody(&quot;if you can read this then the
CSMTPConnection code is working&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtp.SendMessage(m);<br>
</font></p>

<p><font face="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To send your autoexec.bat
as a file attachment to me you would use the following code:</font></p>

<p><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPConnection
smtp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtp.Connect(&quot;mail.yourisp.com&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPMessage m;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
m.AddRecipient(CSMTPAddress(&quot;pjn@indigo.ie&quot;));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.m_From =
CSMTPAddress(&quot;you@someisp.com&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.m_sSubject = &quot;Here's my autoexec.bat
file!&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPAttachment a;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.Attach(&quot;c:\\autoexec.bat&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.AddAttachment(&amp;a);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtp.SendMessage(m);<br>
</font></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><big><a name="History"></a></big><font color="#000000" size="5"><strong>History</strong></font></font></p>

<p><strong><font color="#000000" size="3" face="Arial">V1.0 (26th M</font><font
face="Arial"><font size="3"><font color="#000000">ay</font></font><font color="#000000"
size="3"> 1998)</font></font></strong> 

<ul>
  <li><font face="Arial" color="#000000" size="3">Initial public release.</font></li>
</ul>

<p><font face="Arial" color="#000000" size="3"><strong>V1.1 (17th June 1998)</strong></font>

<ul>
  <li><font face="Arial">Fixed the case where a single dot occurs on its own in the body of a
    message</font></li>
  <li><font face="Arial">Classes now supports an optional &quot;Reply-To&quot; Header Field</font></li>
  <li><font face="Arial">Classes now fully supports file attachments</font></li>
  <li><font face="Arial">Some rework on the contents of the help file</font></li>
</ul>

<p><font face="Arial" color="#000000" size="3"><strong>V1.11 (18th June 1998)</strong></font>

<ul>
  <li><font face="Arial">Fixed a memory overwrite problem which was occurring with the buffer
    used for encoding base64 attachments.</font></li>
</ul>

<p><font face="Arial" color="#000000" size="3"><strong>V1.12 (27th June 1998)</strong></font>

<ul>
  <li><font face="Arial">The case where a line begins with a &quot;.&quot; but contains other
    text is now also catered for. See RFC821, Section 4.5.2 for further details.</font></li>
  <li><font face="Arial">m_sBody in CSMTPMessage has now been made protected. Client
    applications now should call AddBody instead. This ensures that FixSingleDot is only
    called once even if the same message is sent a number of times.</font></li>
  <li><font face="Arial">Fixed a number of problems with how the MIME boundaries were defined
    and sent.</font></li>
  <li><font face="Arial">Got rid of an unreferenced formal parameter compiler warning when
    doing a release build.</font></li>
</ul>

<p><font face="Arial" color="#000000" size="3"><strong>V1.2 (11 August 1998)</strong></font>

<ul>
  <li><font face="Arial">VC 5 project file is now provided instead of VC 4.x</font></li>
  <li><font face="Arial">Attachment array which the message class contains now uses references
    instead of pointers.</font></li>
  <li><font face="Arial">Now uses Sleep(0) to yield our time slice instead of Sleep(100), this
    is the preferred way of writting polling style code in Win32 without serverly impacting
    performance.</font></li>
  <li><font face="Arial">All trace statements now display the value as returned from
    GetLastError</font></li>
  <li><font face="Arial">A number of extra asserts have been added</font></li>
  <li><font face="Arial">AddMultipleRecipients has been added which supports added a number of
    recipients at one time from a single string</font></li>
  <li><font face="Arial">Extra trace statements have been added to help in debugging</font></li>
  <li><font face="Arial">A number of updates to the documentation.</font></li>
</ul>

<p><font face="Arial" color="#000000" size="3"><strong>V1.21 (12 September 1998)</strong></font>

<ul>
  <li><font face="Arial">Removed a couple of unreferenced variable compiler warnings
    discovered when the class was compiled on Visual C++ 6.0.</font></li>
  <li><font face="Arial">Fixed a major bug which was causing an ASSERT when the
    CSMTPAttachment destructor was being called in the InitInstance of the sample app. This
    was inadvertingly introduced for the 1.2 release. The fix is to revert fix 2) as done for
    v1.2. This new fix will also help to reduce the number of attachment images kept in memory
    at one time.</font></li>
  <li><font face="Arial">Fixed a few errors in this help file.</font></li>
</ul>

<p>&nbsp;</p>

<p class="crt"><font face="Arial"><a name="APIReference"></a><big><big><strong>API
Reference</strong></big></big></font></p>

<p><font face="Arial">The API consists of the public member functions of the class
CSMTPAddress, CSMTPMessage &amp; CSMTPConnection</font></p>

<p><a href="#CSMTPAddress"><font face="Arial">CSMTPAddress</font></a><br>
<font face="Arial"><a href="#Attach">CSMTPAttachment::Attach</a><br>
<a href="#GetFilename">CSMTPAttachment::GetFilename</a><br>
<a href="#GetEncodedBuffer">CSMTPAttachment::GetEncodedBuffer</a><br>
<a href="#GetEncodedSize">CSMTPAttachment::GetEncodedSize</a><br>
<a href="#AddRecipient">CSMTPMessage::AddRecipient</a><br>
<a href="#RemoveRecipient">CSMTPMessage::RemoveRecipient</a><br>
<a href="#GetRecipient">CSMTPMessage::GetRecipient</a><br>
<a href="#GetNumberOfRecipients">CSMTPMessage::GetNumberOfRecipients</a><br>
<a href="#AddAttachment">CSMTPMessage::AddAttachment</a><br>
<a href="#RemoveAttachment">CSMTPMessage::RemoveAttachment</a><br>
<a href="#GetAttachment">CSMTPMessage::GetAttachment</a><br>
<a href="#GetNumberOfAttachments">CSMTPMessage::GetNumberOfAttachments</a><br>
<a href="#m_From">CSMTPMessage::m_From</a><br>
<a href="#m_sSubject">CSMTPMessage::m_sSubject</a><br>
<a href="#AddBody">CSMTPMessage::AddBody</a><br>
<a href="#AddMultipleRecipients">CSMTPMessage::AddMultipleRecipients</a><br>
<a href="#m_sXMailer">CSMTPMessage::m_sXMailer</a><br>
<a href="#m_ReplyTo">CSMTPMessage::m_ReplyTo</a><br>
<a href="#Connect">CSMTPConnection::Connect<br>
</a><a href="#Disconnect">CSMTPConnection::Disconnect<br>
</a><a href="#GetLastCommandResponse">CSMTPConnection::GetLastCommandResponse</a><br>
<a href="#GetLastCommandResponseCode">CSMTPConnection::GetLastCommandResponseCode<br>
</a><a href="#GetTimeout">CSMTPConnection::GetTimeout<br>
</a><a href="#SetTimeout">CSMTPConnection::SetTimeout</a><br>
<a href="#SendMessage">CSMTPConnection::SendMessage</a><br>
</font></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a name="CSMTPAddress" href="#CSMTPAddress"></a><font face="Arial"><big><strong>CSMTPAddress</strong></big></font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This class is an encapsulation of an address used in sending an
email. It consists of 2 strings namely m_sFriendlyName and m_sEmailAddress. An example of
constructing an address is:</font></p>

<p><font face="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPAddress
a(_T(&quot;pjn@indigo.ie&quot;)); or<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CSMTPAddress b(_T(&quot;PJ Naughter&quot;),
_T(&quot;pjn@indigo.ie&quot;));</font></p>

<p><font face="Arial">The second form which includes a friendly address allows it to be
used in &quot;To&quot; and &quot;Reply-To&quot; headers in the form &quot;PJ Naughter
&lt;pjn@indigo.ie&gt;&quot;</font></p>

<p><font face="Arial">One public class method is included called GetRegularFormat which
returns the format just discussed.</font></p>

<p><strong><font face="Arial">See Also</font></strong></p>

<p><a href="#Disconnect"><font face="Arial">CSMTPConnection::SendMessage</font></a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a name="Attach"></a><big><font face="Arial"><strong>CSMTPAttachment::Attach</strong></font></big></p>

<p><font face="Arial"><strong>BOOL Attach(const CString&amp; </strong><em>sFilename</em><strong>);</strong></font></p>

<p class="rl"><strong><font face="Arial">Return Value</font></strong></p>

<p class="t"><font face="Arial">TRUE if the file was successfully encoded as an attachment
otherwise FALSE.</font></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>sFilename</em> A reference to the name of the file to setup as
an attachment.</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">Internally this function will perform a base64 encoding of the
specified file and store the encoding in a private buffer ready for use when this
attachment is associated with an SMTP message.</font></p>

<p><font face="Arial"><strong>See Also</strong></font></p>

<p><a href="#AddAttachment"><font face="Arial">CSMTPMessage::AddAttachment</font></a></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -