使用unix框中的c代码邮件

时间:2017-03-15 07:05:45

标签: c unix

我使用下面的代码从我的unix框发送邮件。它编译成功。但我没有收到邮箱中的任何邮件。请帮助我。 我需要为此做任何配置吗?

执行代码后,我在/ usr / spool / mail文件夹中看到了一些文件。 实际上意味着什么?

    char cmd[100];  // to hold the command.
    char to[] = "sample@example.com"; // email id of the recepient.
    char body[] = "SO rocks";    // email body.
    char tempFile[100];     // name of tempfile.

    strcpy(tempFile,tempnam("/tmp","sendmail")); // generate temp file name.

    FILE *fp = fopen(tempFile,"w"); // open it for writing.
    fprintf(fp,"%s\n",body);        // write body to it.
    fclose(fp);             // close it.

    sprintf(cmd,"sendmail %s < %s",to,tempFile); // prepare command.
    system(cmd);     // execute it.

0 个答案:

没有答案