#include "stdafx.h" #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <winsock.h> #pragma comment(lib, "ws2_32.lib") #define cmailserver "gmail-smtp-in.l.google.com" #define cemailto "gonanhack@gmail.com" #define cemailfrom "gonanhack@gmail.com" #define SMTPLog "log.txt" #define cemailsubject "test" #define waittime 30 #define emailmessage "asdfasdfasdfasdfasdfasd" int MailIt(char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char *emailmessage, int maxlen); int main(int argc, char* argv[]) { MailIt(cmailserver, cemailto, cemailfrom, cemailsubject, "asdfsadf", 255); return 0; } int MailIt(char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char *emailmessage, int maxlen) { SOCKET sockfd; WSADATA wsaData; FILE *smtpfile; #define bufsize 300 int bytes_sent; /* Sock FD */ int err; struct hostent *host; /* info from gethostbyname */ struct sockaddr_in dest_addr; /* Host Address */ char line[256+100]; char *Rec_Buf = (char*) malloc(bufsize+1); smtpfile=fopen(SMTPLog,"a+"); if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) { fputs("WSAStartup failed",smtpfile); WSACleanup(); return -1; } if ( (host=gethostbyname(mailserver)) == NULL) { perror("gethostbyname"); exit(1); } memset(&dest_addr,0,sizeof(dest_addr)); memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length); dest_addr.sin_family= host->h_addrtype; dest_addr.sin_port= htons(25); if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) { perror("socket"); exit(1); } fputs("Connecting....\n",smtpfile); if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1) { perror("connect"); exit(1); } Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); strcpy(line,"helo www.gmail.com\n"); fputs(line,smtpfile); bytes_sent=send(sockfd,line,strlen(line),0); Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); strcpy(line,"MAIL FROM:<"); strncat(line,emailfrom,strlen(emailfrom)); strncat(line,">\n",3); fputs(line,smtpfile); bytes_sent=send(sockfd,line,strlen(line),0); Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); strcpy(line,"RCPT TO:<"); strncat(line,emailto,strlen(emailto)); strncat(line,">\n",3); fputs(line,smtpfile); bytes_sent=send(sockfd,line,strlen(line),0); Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); strcpy(line,"DATA\n"); fputs(line,smtpfile); bytes_sent=send(sockfd,line,strlen(line),0); Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); Sleep(waittime); strcpy(line,"To:"); strcat(line,emailto); strcat(line,"\n"); strcat(line,"From:"); strcat(line,emailfrom); strcat(line,"\n"); strcat(line,"Subject:"); strcat(line,emailsubject); strcat(line,"\n"); strcat(line,emailmessage); strcat(line,"\r\n.\r\n"); fputs(line,smtpfile); bytes_sent=send(sockfd,line,strlen(line),0); Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); strcpy(line,"quit\n"); fputs(line,smtpfile); bytes_sent=send(sockfd,line,strlen(line),0); Sleep(waittime); err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0'; fputs(Rec_Buf,smtpfile); fclose(smtpfile); #ifdef WIN32 closesocket(sockfd); WSACleanup(); #else close(sockfd); #endif }
2012년 10월 28일 일요일
Gmail SMTP서버를 이용한 메일 보내기
피드 구독하기:
댓글 (Atom)
UPBIT is a South Korean company, and people died of suicide cause of coin investment.
UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...
-
Intel의 새로운 MMX - "KNI" KNI 는 Katmai New Instruction 의 약자이다 . 아는 분들은 잘 알고있겠지만 KATMAI( 이하 카트마이로 부름 ) 는 인텔의 다음번 펜티엄...
-
구글 문제 귀찮아서 이제 대충 뜻만... In a country in which people only want boys……every family continues to have children until they 남자만 원하는 나라가 있다...
-
[펌] [UNIX/LINUX 명령어] apropos linux 2005/06/28 22:05 수정 삭제 http://blog.naver.com/wiggyz/80014482910 Mr.You의 블로그 | ?? http:...
댓글 없음:
댓글 쓰기
국정원의 댓글 공작을 지탄합니다.