不是等于VM_ 應該是WM_。
創新互聯公司專注為客戶提供全方位的互聯網綜合服務,包含不限于成都網站設計、做網站、金溪網絡推廣、重慶小程序開發公司、金溪網絡營銷、金溪企業策劃、金溪品牌公關、搜索引擎seo、人物專訪、企業宣傳片、企業代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創新互聯公司為所有大學生創業者提供金溪建站搭建服務,24小時服務熱線:028-86922220,官方網址:vcdvsql.cn
WM指的是WindowMessage 即windows消息。
以WM_開頭的是預定義的windows消息。
windows是基于消息驅動的操作系統,當程序接收到系統發送的消息后會做出相應的響應。
例如程序向窗口發送一個 WM_PAINT消息,則窗口會重新繪制。
基本框架就是這,需要其他功能自己添加吧
C語言實現簡單的SMTP發送郵件
#include windows.h
#include stdio.h
#include WinSock.h
#include iostream
using namespace std;
#pragma comment(lib, "ws2_32.lib")
struct Base64Date6
{
unsigned int d4:6;
unsigned int d3:6;
unsigned int d2:6;
unsigned int d1:6;
};
// 協議中加密部分使用的是base64方法
char ConvertToBase64 (char c6);
void EncodeBase64 (char *dbuf, char *buf128, int len);
void SendMail (char *email,char *body);
int OpenSocket (struct sockaddr *addr);
int main()
{
char EmailTo[] = "hanyinlong@126.com";
char EmailContents[] = "From: \"lucy\"hanyinlong@126.com\r\n"
"To: \"dasiy\"hanyinlong@126.com\r\n"
"Subject: Hello\r\n\r\n"
"Hello World, Hello Email!";
SendMail(EmailTo, EmailContents);
return 0;
}
char ConvertToBase64(char uc)
{
if(uc 26)
{
return 'A' + uc;
}
if(uc 52)
{
return 'a' + (uc - 26);
}
if(uc 62)
{
return '0' + (uc - 52);
}
if(uc == 62)
{
return '+';
}
return '/';
}
// base64的實現
void EncodeBase64(char *dbuf, char *buf128, int len)
{
struct Base64Date6 *ddd = NULL;
int i = 0;
char buf[256] = {0};
char *tmp = NULL;
char cc = '\0';
memset(buf, 0, 256);
strcpy_s(buf, 256, buf128);
for(i = 1; i = len/3; i++)
{
tmp = buf + (i-1)*3;
cc = tmp[2];
tmp[2] = tmp[0];
tmp[0] = cc;
ddd = (struct Base64Date6 *)tmp;
dbuf[(i-1)*4+0] = ConvertToBase64((unsigned int)ddd-d1);
dbuf[(i-1)*4+1] = ConvertToBase64((unsigned int)ddd-d2);
dbuf[(i-1)*4+2] = ConvertToBase64((unsigned int)ddd-d3);
dbuf[(i-1)*4+3] = ConvertToBase64((unsigned int)ddd-d4);
}
if(len % 3 == 1)
{
tmp = buf + (i-1)*3;
cc = tmp[2];
tmp[2] = tmp[0];
tmp[0] = cc;
ddd = (struct Base64Date6 *)tmp;
dbuf[(i-1)*4+0] = ConvertToBase64((unsigned int)ddd-d1);
dbuf[(i-1)*4+1] = ConvertToBase64((unsigned int)ddd-d2);
dbuf[(i-1)*4+2] = '=';
dbuf[(i-1)*4+3] = '=';
}
if(len%3 == 2)
{
tmp = buf+(i-1)*3;
cc = tmp[2];
tmp[2] = tmp[0];
tmp[0] = cc;
ddd = (struct Base64Date6 *)tmp;
dbuf[(i-1)*4+0] = ConvertToBase64((unsigned int)ddd-d1);
dbuf[(i-1)*4+1] = ConvertToBase64((unsigned int)ddd-d2);
dbuf[(i-1)*4+2] = ConvertToBase64((unsigned int)ddd-d3);
dbuf[(i-1)*4+3] = '=';
}
return;
}
// 發送郵件
void SendMail(char *email, char *body)
{
int sockfd = {0};
char buf[1500] = {0};
char rbuf[1500] = {0};
char login[128] = {0};
char pass[128] = {0};
WSADATA WSAData;
struct sockaddr_in their_addr = {0};
WSAStartup(MAKEWORD(2, 2), WSAData);
memset(their_addr, 0, sizeof(their_addr));
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(25);
hostent* hptr = gethostbyname("smtp.126.com");
memcpy(their_addr.sin_addr.S_un.S_addr, hptr-h_addr_list[0], hptr-h_length);
printf("IP of smpt.126.com is : %d:%d:%d:%d\n",
their_addr.sin_addr.S_un.S_un_b.s_b1,
their_addr.sin_addr.S_un.S_un_b.s_b2,
their_addr.sin_addr.S_un.S_un_b.s_b3,
their_addr.sin_addr.S_un.S_un_b.s_b4);
// 連接郵件服務器,如果連接后沒有響應,則2 秒后重新連接
sockfd = OpenSocket((struct sockaddr *)their_addr);
memset(rbuf, 0, 1500);
while(recv(sockfd, rbuf, 1500, 0) == 0)
{
cout"reconnect..."endl;
Sleep(2);
sockfd = OpenSocket((struct sockaddr *)their_addr);
memset(rbuf, 0, 1500);
}
coutrbufendl;
// EHLO
memset(buf, 0, 1500);
sprintf_s(buf, 1500, "EHLO HYL-PC\r\n");
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"EHLO REceive: "rbufendl;
// AUTH LOGIN
memset(buf, 0, 1500);
sprintf_s(buf, 1500, "AUTH LOGIN\r\n");
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"Auth Login Receive: "rbufendl;
// USER
memset(buf, 0, 1500);
sprintf_s(buf, 1500, "hanyinlong@126.com");//你的郵箱賬號
memset(login, 0, 128);
EncodeBase64(login, buf, strlen(buf));
sprintf_s(buf, 1500, "%s\r\n", login);
send(sockfd, buf, strlen(buf), 0);
cout"Base64 UserName: "bufendl;
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"User Login Receive: "rbufendl;
// PASSWORD
sprintf_s(buf, 1500, "XXXXXXXXXXXX");//你的郵箱密碼
memset(pass, 0, 128);
EncodeBase64(pass, buf, strlen(buf));
sprintf_s(buf, 1500, "%s\r\n", pass);
send(sockfd, buf, strlen(buf), 0);
cout"Base64 Password: "bufendl;
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"Send Password Receive: "rbufendl;
// MAIL FROM
memset(buf, 0, 1500);
sprintf_s(buf, 1500, "MAIL FROM: hanyinlong@126.com\r\n");
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"set Mail From Receive: "rbufendl;
// RCPT TO 第一個收件人
sprintf_s(buf, 1500, "RCPT TO:%s\r\n", email);
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"Tell Sendto Receive: "rbufendl;
// DATA 準備開始發送郵件內容
sprintf_s(buf, 1500, "DATA\r\n");
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"Send Mail Prepare Receive: "rbufendl;
// 發送郵件內容,\r\n.\r\n內容結束標記
sprintf_s(buf, 1500, "%s\r\n.\r\n", body);
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"Send Mail Receive: "rbufendl;
// QUIT
sprintf_s(buf, 1500, "QUIT\r\n");
send(sockfd, buf, strlen(buf), 0);
memset(rbuf, 0, 1500);
recv(sockfd, rbuf, 1500, 0);
cout"Quit Receive: "rbufendl;
//清理工作
closesocket(sockfd);
WSACleanup();
return;
}
// 打開TCP Socket連接
int OpenSocket(struct sockaddr *addr)
{
int sockfd = 0;
sockfd=socket(PF_INET, SOCK_STREAM, 0);
if(sockfd 0)
{
cout"Open sockfd(TCP) error!"endl;
exit(-1);
}
if(connect(sockfd, addr, sizeof(struct sockaddr)) 0)
{
cout"Connect sockfd(TCP) error!"endl;
exit(-1);
}
return sockfd;
}
使用函數getsockopt獲得發送緩沖區的長度。用法如下:
int sockfd;
int val;
int len;
sockfd = socket (AF_INET, SOCK_STREAM, 0);
len = sizeof (val);
getsockopt( sockfd, SOL_SOCKET, SO_SNDBUF, val, len);
printf ("sndbuf len=%d\n", val);
在32位linux系統上發送緩沖區為16K ,可以使用setsockopt()修改,會影響網絡性能
當前標題:c語言發送郵件的函數 c語言發送post
文章地址:http://vcdvsql.cn/article10/doieogo.html
成都網站建設公司_創新互聯,為您提供網站制作、移動網站建設、響應式網站、網頁設計公司、App設計、網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯