smtp協議 VC實現傳送郵件
利用VC2005實現了郵件傳送,源程式如下:
//-------------------------------------------------------SmtpSendEmail.h------------------------------------
#pragma once
#include <list>
#include <string>
#include <fstream>
#include<WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
#ifndef _SMTPSENDEMAIL_H
#define _SMTPSENDEMAIL_H
//傳送執行緒
DWORD WINAPI SendMailThread(LPVOID lpParam);
class SmtpSendEmail
{
public:
SmtpSendEmail(void);
virtual ~SmtpSendEmail(void);
public:
void SetPost( int nPost );
void SetHost( string strHost );
void SetAccount( string strAccount );
void SetPassword( string strPassword );
void SetMailFrom( string strMailFrom );
void SetSendTo( string strSendTo );
void SetSubject( string strSubject );
void SetDateTime( string strDateTime );
bool AddDataFromString( string strData );
bool AddDataFromBuffer( char* szData, int iLen );
bool AddDataFromFile( string strFileName );
bool AddAttachedFile( string strFilePath, string strFileName );
bool SandThread();
bool StarMailThread();
private:
int Base64EncodeLen( int nSrcLen );
bool Base64Encode( const BYTE* szSrcData, int nSrcLen, BYTE* szDestData, int* pnDestLen );
bool CheckResponse(int nResCode);
bool ConnectServ();
bool SendHelo();
bool SendEhlo();
bool AutoLogin();
bool EmailFrom();
bool EmailTo();
bool DataServ();
bool SendData();
bool SendAttachedFile();
bool QuitServ();
private:
static const char m_szBase64CodeTable[];
static const string MIMEMultipartMixedLogin;
static const string MIMETextPlainLogin;
static const string MyBoundary;
static const string CTCodeQP;
static const string CTCodeBase64;
static const string CTTextPlainCharCodeGB2312;
static const string CTAppOctetStreamName;
static const string CDAttachemntFileName;
struct SMTPSTRU
{
int nPost;
string strHost;
string strAccount;
string strPassword;
string strMailFrom;
string strSendTo;
string strSubject;
string strDateTime;
string strData;
};
struct FILEINFOSTRU
{
string strPath;
string strFile;
};
SOCKET m_hSocket;
SMTPSTRU m_smtpPro;
list<FILEINFOSTRU> m_listFileInfo;
};
#endif
//------------------------------------------------SmtpSendEmail.cpp------------------------------------------------------
#include "StdAfx.h"
#include "SmtpSendEmail.h"
//傳送執行緒
DWORD WINAPI SendMailThread(LPVOID lpParam)
{
((SmtpSendEmail*)lpParam)->SandThread();
return 0;
}
const char SmtpSendEmail::m_szBase64CodeTable[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" };
const string SmtpSendEmail::MIMEMultipartMixedLogin = "X-Mailer: Gddsky mailer\r\n MIME-Version: 1.0\r\nContent-type: multipart/mixed;boundary=\"===_000_Gddsky_000_===\"\r\n\r\n";
const string SmtpSendEmail::MIMETextPlainLogin = "X-Mailer: Gddsky mailer\r\nMIME-Version: 1.0\r\nContent-type: text/plain;charset=\"GB2312\"\r\n Content-Transfer-Encoding: base64\r\n\r\n";
const string SmtpSendEmail::MyBoundary = "\r\n--===_000_Gddsky_000_===\r\n";
const string SmtpSendEmail::CTCodeQP = "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
const string SmtpSendEmail::CTCodeBase64 = "Content-Transfer-Encoding: base64\r\n\r\n";
const string SmtpSendEmail::CTTextPlainCharCodeGB2312 = "Content-Type: text/plain;charset=\"GB2312\"\r\n";
const string SmtpSendEmail::CTAppOctetStreamName = "Content-Type: application/octet-stream;name=";
const string SmtpSendEmail::CDAttachemntFileName = "Content-Disposition: attachment;filename=";
SmtpSendEmail::SmtpSendEmail(void)
{
WSADATA wsaData = {0};
WORD wVersionRequested = MAKEWORD( 2, 2 );
WSAStartup( wVersionRequested, &wsaData );
m_smtpPro.nPost = 25;
m_hSocket = 0;
}
SmtpSendEmail::~SmtpSendEmail(void)
{
m_listFileInfo.clear();
//關閉SOCK
closesocket(m_hSocket);
m_hSocket = 0;
WSACleanup();
}
int SmtpSendEmail::Base64EncodeLen( int nSrcLen )
{
int nRet = nSrcLen * 4 / 3 + nSrcLen % 3;
int nCRLFs = ( nRet / 76 + 1 ) * 2;
int nOnLastLine = nRet % 76;
nRet += nCRLFs;
if( nOnLastLine && nOnLastLine % 4 )
{
nRet += 4 - ( nOnLastLine % 4 );
}
return nRet;
}
bool SmtpSendEmail::Base64Encode( const BYTE* szSrcData, int nSrcLen, BYTE* szDestData, int* pnDestLen )
{
if( !( szSrcData && nSrcLen && szDestData && pnDestLen && *pnDestLen ) )
{
return false;
}
if( *pnDestLen < Base64EncodeLen( nSrcLen ) )
{
return false;
}
int nWritten = 0 ;
int nLen1 = ( nSrcLen / 3 ) * 4;
int nLen2 = nLen1 / 76;
int nLen3 = 19;
for( int i = 0; i <= nLen2; i++ )
{
if( i == nLen2 )
{
nLen3 = ( nLen1 % 76 ) / 4;
}
for( int j = 0; j < nLen3; j++ )
{
DWORD dwCurr = 0;
for( int n = 0; n < 3; n++ )
{
dwCurr |= *szSrcData++;
dwCurr <<= 8;
}
for( int k = 0; k < 4; k++ )
{
BYTE b = ( BYTE )( dwCurr >> 26 );
*szDestData++ = m_szBase64CodeTable[ b ];
dwCurr <<= 6;
}
}
nWritten += nLen3 * 4;
*szDestData++ = '\r';
*szDestData++ = '\n';
nWritten+= 2;
}
if( nWritten )
{
szDestData-= 2;
nWritten -= 2;
}
nLen2 = ( nSrcLen % 3 ) ? ( nSrcLen % 3 ) + 1 : 0;
if( nLen2 )
{
DWORD dwCurr = 0;
for( int n = 0; n < 3; n++ )
{
if( n < ( nSrcLen % 3 ) )
{
dwCurr |= *szSrcData++;
}
dwCurr <<= 8;
}
for( int k = 0; k < nLen2; k++ )
{
BYTE b = ( BYTE ) ( dwCurr >> 26 );
*szDestData++ = m_szBase64CodeTable[ b ];
dwCurr <<= 6;
}
nWritten += nLen2;
nLen3 = nLen2 ? 4 - nLen2 : 0;
for( int j = 0; j < nLen3; j++ )
{
*szDestData++ = '=';
}
nWritten += nLen3;
}
*pnDestLen = nWritten;
return true;
}
void SmtpSendEmail::SetPost( int nPost )
{
m_smtpPro.nPost = nPost;
}
void SmtpSendEmail::SetHost( string strHost )
{
m_smtpPro.strHost = strHost;
}
void SmtpSendEmail::SetAccount( string strAccount )
{
m_smtpPro.strAccount = strAccount;
}
void SmtpSendEmail::SetPassword( string strPassword )
{
m_smtpPro.strPassword = strPassword;
}
void SmtpSendEmail::SetMailFrom( string strMailFrom )
{
m_smtpPro.strMailFrom = strMailFrom;
}
void SmtpSendEmail::SetSendTo( string strSendTo )
{
m_smtpPro.strSendTo = strSendTo;
}
void SmtpSendEmail::SetSubject( string strSubject )
{
m_smtpPro.strSubject = strSubject;
}
void SmtpSendEmail::SetDateTime( string strDateTime )
{
m_smtpPro.strDateTime = strDateTime;
}
bool SmtpSendEmail::AddDataFromString( std::string strData )
{
m_smtpPro.strData.append( strData.c_str() );
return true;
}
bool SmtpSendEmail::AddDataFromBuffer( char* szData, int iLen )
{
if( NULL != szData && iLen > 0)
{
m_smtpPro.strData.append( szData, iLen );
return true;
}
return false;
}
bool SmtpSendEmail::AddDataFromFile( string strFileName )
{
ifstream InputFile;
InputFile.open( strFileName.c_str(), ios_base::binary | ios_base::in );
if( InputFile.fail() )
{
return false;
}
InputFile.seekg( 0, ios_base::end );
int iLen = InputFile.tellg();
InputFile.seekg( 0, ios_base::beg );
char* pszFileData = new char[iLen + 1];
memset(pszFileData, 0, iLen + 1);
InputFile.read( pszFileData, iLen );
m_smtpPro.strData.append( pszFileData );
delete pszFileData;
return true;
}
bool SmtpSendEmail::AddAttachedFile(string strFilePath, string strFileName)
{
FILEINFOSTRU fileInfo;
fileInfo.strPath = strFilePath;
fileInfo.strFile = strFileName;
m_listFileInfo.push_back(fileInfo);
return true;
}
bool SmtpSendEmail::StarMailThread()
{
DWORD threadID;
HANDLE threadHandle = CreateThread(0, 0, SendMailThread, this, 0, &threadID);
return true;
}
// 傳送郵件
bool SmtpSendEmail::SandThread()
{
//建立SOCK,連線伺服器
if (!ConnectServ())
{
return false;
}
//HELO CMD
if(!SendHelo())
{
return false;
}
//EHLO CMD
if (SendEhlo())
{
if (!AutoLogin())
{
return false;
}
}
//MAIL FORM CMD
if (!EmailFrom())
{
return false;
}
//RCPT TO CMD
if (!EmailTo())
{
return false;
}
//DATA CMD
if (!DataServ())
{
return false;
}
// 郵件內容
if (m_listFileInfo.size() > 0)
{
if (!SendAttachedFile())
{
return false;
}
}
else
{
if (!SendData())
{
return false;
}
}
// 傳送結束
if (!QuitServ())
{
return false;
}
//關閉SOCK
closesocket(m_hSocket);
m_hSocket = 0;
return true;
}
bool SmtpSendEmail::ConnectServ()
{
//建立SOCK
m_hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
//超時
struct timeval timeoutRecv = {0};
timeoutRecv.tv_sec = 30000;
setsockopt(m_hSocket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeoutRecv, sizeof(timeoutRecv));
//連線
LPHOSTENT pHost = gethostbyname(m_smtpPro.strHost.c_str());
struct sockaddr_in servAddr;
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = *(ULONG *)pHost->h_addr_list[0];
servAddr.sin_port = htons(25);
if (connect(m_hSocket, (const struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
return CheckResponse(220);
}
bool SmtpSendEmail::CheckResponse(int nResCode)
{
char szRecvBuf[1024] = {0};
char szTemp[20] = {0};
_itoa_s(nResCode, szTemp, 20, 10);
//接收回復
int nRecvLen = recv(m_hSocket, szRecvBuf, 1024, 0);
if (nRecvLen <= 0)
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
if (nRecvLen >= (int)strlen(szTemp))
{
if (strstr(szRecvBuf, szTemp) != NULL)
{
return true;
}
}
return false;
}
bool SmtpSendEmail::SendHelo()
{
string strSendBuf;
strSendBuf.append( "HELO " );
strSendBuf.append(m_smtpPro.strHost.c_str());
strSendBuf.append("\r\n");
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(250);
}
bool SmtpSendEmail::SendEhlo()
{
string strSendBuf;
strSendBuf.append( "EHLO 126.com \r\n" );
//strSendBuf.append(m_smtpPro.Host.c_str());
//strSendBuf.append("\r\n");
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(250);
}
bool SmtpSendEmail::AutoLogin()
{
int nTemp = 1024;
char szBaseBuf[1024] = {0};
string strSendBuf;
strSendBuf.append( "AUTH LOGIN\r\n" );
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
if (!CheckResponse(334))
{
return false;
}
//帳戶
strSendBuf.clear();
Base64Encode( (const BYTE*)m_smtpPro.strAccount.c_str(), (int)m_smtpPro.strAccount.size(), (BYTE*)szBaseBuf, &nTemp );
strSendBuf.append( szBaseBuf );
//傳送
nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
if (!CheckResponse(334))
{
return false;
}
//密碼
strSendBuf.clear();
nTemp = 1024;
memset(szBaseBuf, 0, 1024 );
Base64Encode( (const BYTE*)m_smtpPro.strPassword.c_str(), (int)m_smtpPro.strPassword.size(), (BYTE*)szBaseBuf, &nTemp );
strSendBuf.append( szBaseBuf );
//傳送
nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(235);
}
bool SmtpSendEmail::EmailFrom()
{
string strSendBuf;
strSendBuf.append( "MAIL FROM: <" );
strSendBuf.append( m_smtpPro.strMailFrom.c_str() );
strSendBuf.append( ">\r\n" );
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(250);
}
bool SmtpSendEmail::EmailTo()
{
string strSendBuf;
strSendBuf.append( "RCPT TO: <" );
strSendBuf.append( m_smtpPro.strSendTo.c_str() );
strSendBuf.append( ">\r\n" );
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(250);
}
bool SmtpSendEmail::DataServ()
{
string strSendBuf;
strSendBuf.append( "DATA\r\n" );
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(354);
}
bool SmtpSendEmail::SendData()
{
string strSendBuf;
strSendBuf.append( "From: <" );
strSendBuf.append( m_smtpPro.strMailFrom.c_str() );
strSendBuf.append( ">\r\n" );
strSendBuf.append( "To: <" );
strSendBuf.append( m_smtpPro.strSendTo.c_str() );
strSendBuf.append( ">\r\n" );
strSendBuf.append( "Date: " );
strSendBuf.append( m_smtpPro.strDateTime.c_str() );
strSendBuf.append( "\r\n" );
strSendBuf.append( "Subject: " );
strSendBuf.append( m_smtpPro.strSubject.c_str() );
strSendBuf.append( "\r\n" );
strSendBuf.append( MIMETextPlainLogin.c_str() );
//內容
strSendBuf.append(m_smtpPro.strData.c_str());
//結束符
strSendBuf.append("\r\n.\r\n");
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(250);
}
bool SmtpSendEmail::SendAttachedFile()
{
string strSendBuf;
strSendBuf.append( "From: <" );
strSendBuf.append( m_smtpPro.strMailFrom.c_str() );
strSendBuf.append( ">\r\n" );
strSendBuf.append( "To: <" );
strSendBuf.append( m_smtpPro.strSendTo.c_str() );
strSendBuf.append( ">\r\n" );
strSendBuf.append( "Date: " );
strSendBuf.append( m_smtpPro.strDateTime.c_str() );
strSendBuf.append( "\r\n" );
strSendBuf.append( "Subject: " );
strSendBuf.append( m_smtpPro.strSubject.c_str() );
strSendBuf.append( "\r\n" );
strSendBuf.append( MIMEMultipartMixedLogin.c_str() );
strSendBuf.append( MyBoundary.c_str() );
strSendBuf.append( CTTextPlainCharCodeGB2312.c_str() );
strSendBuf.append( CTCodeBase64.c_str() );
//內容加密
int nSize = Base64EncodeLen( (int)m_smtpPro.strData.size() );
BYTE *pszDataBuf = new BYTE[nSize+1];
memset(pszDataBuf, 0, nSize+1);
Base64Encode( (const BYTE*)m_smtpPro.strData.c_str(), (int)m_smtpPro.strData.size(), (BYTE*)pszDataBuf, &nSize );
strSendBuf.append((char*)pszDataBuf);
delete pszDataBuf;
//傳送
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//附件
for( list<FILEINFOSTRU>::iterator it = m_listFileInfo.begin(); it != m_listFileInfo.end(); it++ )
{
string strFile = ( *it ).strPath + ( *it ).strFile;
string strFileData;
// 讀檔案
ifstream InputFile;
InputFile.open( strFile.c_str(), ios_base::binary | ios_base::in );
if( InputFile.fail() )
{
continue;
}
InputFile.seekg( 0, ios_base::end );
int iLen = InputFile.tellg();
InputFile.seekg( 0, ios_base::beg );
strFileData.resize( iLen );
InputFile.read( (char*)strFileData.c_str(), iLen );
// 加入一個附件頭
strSendBuf.clear();
strSendBuf.append( MyBoundary.c_str() );
strSendBuf.append( CTAppOctetStreamName.c_str() );
strSendBuf.append( ( *it ).strFile.c_str() );
strSendBuf.append( "\r\n" );
strSendBuf.append( CDAttachemntFileName.c_str() );
strSendBuf.append( ( *it ).strFile.c_str() );
strSendBuf.append( "\r\n" );
strSendBuf.append( CTCodeBase64.c_str() );
//內容加密
nSize = Base64EncodeLen( (int)strFileData.size() );
pszDataBuf = new BYTE[nSize+1];
memset(pszDataBuf, 0, nSize+1);
Base64Encode( (const BYTE*)strFileData.c_str(), (int)strFileData.size(), (BYTE*)pszDataBuf, &nSize );
strSendBuf.append((char*)pszDataBuf);
delete pszDataBuf;
//傳送
nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
}
//結束符
strSendBuf.clear();
strSendBuf.append("\r\n.\r\n");
//傳送
nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(250);
}
bool SmtpSendEmail::QuitServ()
{
string strSendBuf = "QUIT\r\n";
int nSendLen = send(m_hSocket, strSendBuf.c_str(), (int)strSendBuf.size(), 0);
if (nSendLen != (int)strSendBuf.size())
{
closesocket(m_hSocket);
m_hSocket = 0;
return false;
}
//回覆
return CheckResponse(221);
}
測試程式碼:
m_smtp.SetHost("smtp.126.com");
m_smtp.SetPost(25);
m_smtp.SetAccount("yefeng654321");
m_smtp.SetPassword("密碼");
m_smtp.SetMailFrom(" [email protected]");
m_smtp.SetSendTo("[email protected]");
m_smtp.SetSubject("測試");
m_smtp.SetDateTime("2008-12-29");
m_smtp.AddDataFromBuffer("123456789", 9);
m_smtp.AddAttachedFile("c:\\","1.txt");
m_smtp.StarMailThread();
相關推薦
smtp協議 VC實現傳送郵件
利用VC2005實現了郵件傳送,源程式如下: //-------------------------------------------------------SmtpSendEmail.h------------------------------------ #pr
基於SMTP協議的CMD命令郵件傳送
網上有不少的這類的文章,以是參照這些文章後,自己實際執行的結果。系統使用的是WIN7 旗艦版。 1.開啟CMD命令後,連線到SMTP伺服器,如連線到QQ的SMTP服務,輸入命令 telnet smtp.qq.com 25,見下圖,其中25為SMTP協議的預設埠, 2.基
單純java程式碼實現傳送郵件
這個是工具類直接執行main方法就可以傳送郵箱,細節方面看我另一篇文章 https://mp.csdn.net/postedit/84307897 package com.bgs.controller; import javax.mail.Authenticator
node.js實現傳送郵件功能
準備事項 QQ郵箱設定:進入QQ郵箱->設定->賬戶->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務->開啟POP3/SMTP服務,並複製pass祕鑰 安裝nodemailer :npm install nodem
python實現傳送郵件
本文目錄 一 使用SMTP模組傳送郵件 二 傳送html格式郵件 三 傳送帶附件的郵件 四 Django傳送郵件 各大郵箱smtp伺服器及埠 qq郵箱配置smtp 一 使用SMTP模組傳送郵件
log4j實現傳送郵件功能
引言 最近預上線的一個機器人專案,因為這個專案中有很多的AI的東西,整個專案分為三部分組成,web工程——FS——NLU,整個web工程都是由我來負責,後面兩部分有大資料部門的東西負責,因為後面這兩部分對於我們貸後行業來說都是比較超前的,所以在整個連調的過程中會有很多的異常
JAVAmail簡單實現傳送郵件
Android在郵件客戶端的設計中,有兩種實現方法: 一、呼叫Android系統自帶的郵件服務 ,這種方法簡單易用,但是傳送郵件的賬號必須是gmail賬號 二、採用javamail功能包進行設計,不必侷限於特定郵箱,但是比前一種較麻煩 1、使用Android 自帶的
wordpress使用阿里雲郵件推送服務實現傳送郵件
之前用騰迅雲時,配置了wordpress是可以使用郵件服務的,然而到了阿里雲,卻無法使用了,有人說是因為阿里雲關了25埠,但騰迅好像也關了。 百度看看有沒有其他方法,最終讓我找到個方法,可惜不是很完美,就是使用阿里雲郵件推送服務,不過只能免費傳送200封郵件。。。當然,總比沒有好 開啟網址是這樣的,如果沒有話
TempletMail 實現傳送郵件
話不多說,實現功能為主 1、引入phpmailer, 2、初始化(TP框架中) if ((new TempletMail())->OrdertenantSuccessful($info['email'], '', [])) { } else { } p
jmeter- 發現jmeter3.2版本SMTP sampler外掛無法傳送郵件
小編最近在寫自動化框架時,發現jmeter3.2版本的SMTP sampler 無法傳送郵件。 進過小編仔細的認證發現這個問題是3.2版本的BUG; 相同的指令碼,在3.1是OK的,在3.2就報錯,後來小編就在apache 的官方網站提交了BUG。“https://bz.ap
利用smtp協議傳送帶附件的郵件
之前寫過一個發郵件的,不過沒帶附檔,今天再看了下smtp協議,做了個帶附檔的郵件傳送例子,也就這樣吧。 package main /* 瞭解下smtp協議,並做了個小演示: 利用Go自帶的net/smtp包,傳送帶附檔的郵件。 Author: XCL
實現傳送郵件功能
原文出自:www.hangge.com 轉載請保留原文連結:http://www.hangge.com/blog/cache/detail_792.html 使用MessageUI.framework框架除了可以傳送簡訊,還能傳送Email,步驟如下: (
JavaWeb中使用JavaMail實現傳送郵件功能例項詳解
現在很多的網站都提供有使用者註冊功能, 通常我們註冊成功之後就會收到一封來自注冊網站的郵件。郵件裡面的內容可能包含了我們的註冊的使用者名稱和密碼以及一個啟用賬戶的超連結等資訊。今天我們也來實現一個這樣的功能,使用者註冊成功之後,就將使用者的註冊資訊以Email的形式傳送到使
JAVA實現傳送郵件功能
/** * 傳送郵件功用方法 * @param mailTo * @param html * @param userName */ public void sendEmployeeCommon(String mailTo , String html , Stri
iOS 實現傳送郵件和簡訊
- (void)businessContactWithMail { Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); if (mailClass != nil) { // We
thinkphp5中使用phpmailer實現傳送郵件功能
一、開啟SMTP服務(使用php傳送郵件需要用到SMTP服務,這裡以163郵箱的SMTP服務為例)。 1.登入163郵箱,在首頁上找到“設定”。 2.選擇開啟的服務,一般都全選,POP3/SMTP/IMAP,開啟SMTP服務就得先開通客戶授權碼。 3.點選開通客戶授權
thinkphp5中使用phpmailer實現傳送郵件功能 及自己遇到的坑
一、開啟SMTP服務(使用php傳送郵件需要用到SMTP服務,這裡以163郵箱的SMTP服務為例)。 1.登入163郵箱,在首頁上找到“設定”。 2.選擇開啟的服務,一般都全選,POP3/SMTP/IMAP,開啟SMTP服務就得先開通客戶授權碼。 3.點選
使用javamail實現傳送郵件
1.需求 公司有個需求要將頻繁登入伺服器的ip地址及時進行郵件和簡訊報警,故要寫一個傳送郵件和簡訊的程式 2.問題描述 從網上down了一些java程式碼,不是較為理想,大部分都使用javamail來實現,傳送到網易郵箱沒什麼問題,但qq郵箱不行,網易郵箱
wordpress配置smtp功能後無法傳送郵件的原因|
前幾天搭建了一個wordpress部落格,歡迎大家去參觀,點選這裡 之後想用SMTP配置一個可以郵件訂閱的功能,用自己的其他郵箱訂閱之後,卻怎麼也收不到郵件。百度了很多辦法,都沒什麼用。 網上的文章抄來抄去真是一個比一個無恥!不負責任的亂複製簡直誤導了很多小
ASP.NET 實現傳送郵件 + 多個收件人 + 多個附件
最近專案中需要實現傳送郵件+新增附件的功能,於是又學習了一下System.Net.Mail.MailMessage和System.Net.Mail.SmtpClient等幾個.Net中發郵件的幾個類,根據網上的一些程式碼,做了一個小Demo分享一下。