- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
char* CFastSmtp::_formatHeader()
{
// check for at least one recipient
if(Recipients.size() <= 0 ) {
printf("Please add a message recipient!\r\n");
return NULL;
}
int s=0;
char *msgHeader = new char[16385];
//char to[1024];
for (unsigned int i=s=0;i<Recipients.size();i++) {
s+=strlen(Recipients.at(i)->GetEmail())+1;
} if (s==0) s=1; char *to = new char[s];
//char cc[1024];
for (i=s=0;i<CCRecipients.size();i++) {
s+=strlen(CCRecipients.at(i)->GetEmail())+1;
} if (s==0) s=1; char *cc = new char[s];
//char bcc[1024];
for (i=s=0;i<BCCRecipients.size();i++) {
s+=strlen(BCCRecipients.at(i)->GetEmail())+1;
} if (s==0) s=1; char *bcc = new char[s];
TCHAR szDate[500];
TCHAR sztTime[500];
// create the recipient string, cc string, and bcc string
to[0] = '\0';
for (i=0;i<Recipients.size();i++) {
i > 0 ? strcat(to,","):strcat(to,"");
strcat(to,Recipients.at(i)->GetEmail());
}
cc[0] = '\0';
for (i=0;i<CCRecipients.size();i++) {
i > 0 ? strcat(cc,","):strcat(cc,"");
strcat(cc,CCRecipients.at(i)->GetEmail());
}
bcc[0] = '\0';
for (i=0;i<BCCRecipients.size();i++) {
i > 0 ? strcat(bcc,","):strcat(bcc,"");
strcat(bcc,BCCRecipients.at(i)->GetEmail());
}
// get the current date and time
SYSTEMTIME st={0};
::GetSystemTime(&st);
::GetDateFormat(LOCALE_SYSTEM_DEFAULT,0,&st,"ddd',
' dd MMM yyyy",szDate,sizeof(szDate));
::GetTimeFormat(LOCALE_SYSTEM_DEFAULT,TIME_FORCE24HOURFORMAT,&st,
"HH':'mm':'ss tt",sztTime,sizeof(sztTime));
// here it is...the main data of the message
wsprintf(msgHeader,"DATE: %s %s\r\n", szDate, sztTime);
if (m_pcFromName != NULL) {
strcat(msgHeader,"FROM: ");
strcat(msgHeader, m_pcFromName);
strcat(msgHeader, "\r\n");
}
strcat(msgHeader,"To: ");
strcat(msgHeader, to);
strcat(msgHeader, "\r\n");
strcat(msgHeader,"Cc: ");
strcat(msgHeader, cc);
strcat(msgHeader, "\r\n");
if (m_pcSubject != NULL) {
strcat(msgHeader, "Subject: ");
strcat(msgHeader, m_pcSubject);
strcat(msgHeader, "\r\n");
}
if (m_pcXMailer != NULL) {
strcat(msgHeader,"X-Mailer: ");
strcat(msgHeader, m_pcXMailer);
strcat(msgHeader, "\r\n");
}
// start optional fields
if (m_pcReplyTo != NULL) {
strcat(msgHeader, "Reply-To: ");
strcat(msgHeader, m_pcReplyTo);
strcat(msgHeader, "\r\n");
}
// start MIME versions
strcat(msgHeader,
"MIME-Version: 1.0\r\nContent-type: text/plain; charset=US-ASCII\r\n");
// send header finish command
strcat(msgHeader, "\r\n");
// clean up
delete to;
delete cc;
delete bcc;
// done
return msgHeader;
}