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

📄 sender.cpp

📁 网页上mail组件
💻 CPP
字号:
// Sender.cpp : Implementation of CSender
#include "stdafx.h"
#include "EMail.h"
#include "Sender.h"

/////////////////////////////////////////////////////////////////////////////
// CSender


STDMETHODIMP CSender::SetSMTP(BSTR i_bsSmtp)
{
	USES_CONVERSION;
	LPSTR szSmtp=W2A(i_bsSmtp);

	m_SendMail.SetSMTP(szSmtp);

	return S_OK;
}

STDMETHODIMP CSender::From(BSTR i_bsFrom)
{
	USES_CONVERSION;
	LPSTR szFrom=W2A(i_bsFrom);

	m_SendMail.SetFrom(szFrom);

	return S_OK;
}

STDMETHODIMP CSender::To(BSTR i_bsTo)
{
	USES_CONVERSION;
	LPSTR szTo=W2A(i_bsTo);

	if(!m_bTo)
	{
		m_SendMail.SetTo(szTo);
		m_bTo=TRUE;
	}
	else
	{
		LIST *pNext;

		pNext=new LIST;
		pNext->pNext=NULL;
		pNext->szRcpt=new char[strlen(szTo)+1];
		strcpy(pNext->szRcpt,szTo);

		if(pCC==NULL)
			pCC=pNext;		
		else
		{
			LIST *pCur=pCC;
			while(pCur->pNext!=NULL)
				pCur=pCur->pNext;
			pCur->pNext=pNext;
		}
	}

	return S_OK;
}

STDMETHODIMP CSender::Send(BSTR i_bsSubject, BSTR i_bsContent)
{
	USES_CONVERSION;
	LPSTR szSubject=W2A(i_bsSubject);
	LPSTR szContent=W2A(i_bsContent);
	RCPT rcpt;
	UINT count;
	LIST *pNext;
	rcpt.Length=64;

	//Set RCPT : copy from the list and delete the list
	//			 copy from the RCPT and delete the rcpt

	if(!pCC)
		goto SETATTACHMENT;

	rcpt.Count=0;
	pNext=pCC;
	while(pNext!=NULL)
	{
		if(strlen(pNext->szRcpt)<64)
			rcpt.Count++;
		pNext=pNext->pNext;
	}
	rcpt.szRcpt=new char[rcpt.Count*64];
	pNext=pCC;
	count=0;
	while(pNext!=NULL)
	{
		if(strlen(pNext->szRcpt)<64)
			strcpy(&(rcpt.szRcpt[64*count]),pNext->szRcpt);		
		pNext=pNext->pNext;
		count++;
	}
	pNext=pCC;
	while(pNext!=NULL)
	{
		LIST *tmp;
		tmp=pNext;
		pNext=pNext->pNext;
		delete []tmp->szRcpt;
		delete tmp;
	}
	pCC=NULL;
	m_SendMail.SetRCPT(&rcpt);
	delete []rcpt.szRcpt;

	//Set Attachment: copy from the list and delete the list
	//			 copy from the RCPT and delete the rcpt
SETATTACHMENT:

	if(!pAttachment)
		goto SENDMAIL;

	rcpt.Count=0;
	pNext=pAttachment;
	while(pNext!=NULL)
	{
		if(strlen(pNext->szRcpt)<64)
			rcpt.Count++;
		pNext=pNext->pNext;
	}
	rcpt.szRcpt=new char[rcpt.Count*64];
	pNext=pAttachment;
	count=0;
	while(pNext!=NULL)
	{
		if(strlen(pNext->szRcpt)<64)
			strcpy(&(rcpt.szRcpt[64*count]),pNext->szRcpt);		
		pNext=pNext->pNext;
		count++;
	}
	pNext=pAttachment;
	while(pNext!=NULL)
	{
		LIST *tmp;
		tmp=pNext;
		pNext=pNext->pNext;
		delete []tmp->szRcpt;
		delete tmp;
	}


	//Send the mail
SENDMAIL:
	m_SendMail.SetHello();
	if(pAttachment)
	{
		m_SendMail.DataMIME(szSubject,szContent,strlen(szContent),&rcpt);
		delete []rcpt.szRcpt;
	}
	else
		m_SendMail.DataNormal(szSubject,szContent,strlen(szContent));
	m_SendMail.SendMail();

	pCC=NULL;
	pAttachment=NULL;
	m_bTo=FALSE;
	return S_OK;
}

STDMETHODIMP CSender::AddAttachment(BSTR i_bsAttachmentPath)
{
	USES_CONVERSION;
	LPSTR szAttachmentPath=W2A(i_bsAttachmentPath);

	LIST *pNext;

	pNext=new LIST;
	pNext->pNext=NULL;
	pNext->szRcpt=new char[strlen(szAttachmentPath)+1];
	strcpy(pNext->szRcpt,szAttachmentPath);

	if(pAttachment==NULL)
		pAttachment=pNext;		
	else
	{
		LIST *pCur=pAttachment;
		while(pCur->pNext!=NULL)
			pCur=pCur->pNext;
		pCur->pNext=pNext;
	}

	return S_OK;
}

⌨️ 快捷键说明

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