用C发送带有附件的电子邮件

时间:2020-04-03 00:21:27

标签: c smtp

您好,我正在编写一个C语言程序,该程序将一些文件发送到电子邮件地址。我已经让它发送电子邮件了,但是我不知道如何发送附件,我用Google搜索了它,发现的唯一一件事就是使用DATA \ n命令后必须将其发送到smtp服务器。

#include <stdio.h>
#include <winsock2.h>
#include <windows.h>


int main(int argc, char **argv)
{
    WORD version = MAKEWORD(1,2);
    WSADATA data;
    int error;
    error = WSAStartup(version,&data);   

    SOCKET s = socket(AF_INET,SOCK_STREAM,0);
    SOCKADDR_IN saddr;
    saddr.sin_family = AF_INET;
    saddr.sin_port = htons(25);
    saddr.sin_addr.s_addr = inet_addr("173.194.76.26");

    char Antwort[1000]; int len;
    error = connect(s,(SOCKADDR*)&saddr,sizeof(saddr));
    len = recv(s,Antwort,1000,0);
    printf("\n\n%s",Antwort);
        send(s,"HELO dieseitegibtsnicht.de\n",strlen("HELO dieseitegibtsnicht.de\n"),0);
    recv(s,Antwort,1000,0);
    printf("\n\n%s",Antwort);
        send(s,"MAIL FROM: <maxmustermann@gmail.com>\n",strlen("MAIL FROM: <maxmustermann@gmail.com>\n"),0);
    recv(s,Antwort,1000,0);
    printf("\n\n%s",Antwort);
        send(s,"RCPT TO: <CENSORED@gmail.com>\n",strlen("RCPT TO: <CENSORED@gmail.com>\n"),0);
    recv(s,Antwort,1000,0);
    printf("\n\n%s",Antwort);
        send(s,"DATA\n",strlen("DATA\n"),0);
    recv(s,Antwort,1000,0);
    printf("\n\%s",Antwort);
    char msg[300] = "TO: CENSORED@gmail.com\nFROM: maxmustermann@gmail.com\nSUBJECT: Irgendwas\nDas hier kann hier eh keiner lesen\r\n.\r\n";
        send(s,msg,strlen(msg),0);
    recv(s,Antwort,1000,0);
    printf("\n\n%s",Antwort);
        send(s,"QUIT\n",strlen("QUIT\n"),0);
    recv(s,Antwort,1000,0);
    printf("\n\n%s",Antwort);
}

0 个答案:

没有答案