• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 803
  • Last Modified:

sendmail problem

Hi,

I have problems with using sendmail...here is my program...what should I change?

void send_email(const char *mail_from, const char *mail_to, char *message)
{
  FILE *mail;
  char sendmail_path[256];

  sprintf(sendmail_path, "/usr/lib/sendmail &s", mail_to);
  mail = popen(sendmail_path,"w");
  fprintf(mail,"Reply-to: %s\n",mail_from);
  fprintf(mail,"From: %s\n",mail_from);
  fprintf(mail,"To: %s\n",mail_to);
  fprintf(mail,"Subject: %sError Notification\n");
  fprintf(mail,"MIME-Version: 1.0\n");
  fprintf(mail,"Content-Type: text/html\n\n");
  fprintf(mail,message);
  fprintf(mail,"\r\n");
  pclose(mail);
}

and I got this error message "Recipient names must be specified" (such as: mail_to = xenia@aaa.com)
what should I do with my code?  Or what's wrong with my code?


Xenia
0
xenia27
Asked:
xenia27
  • 9
  • 6
1 Solution
 
brettmjohnsonCommented:
Your sprintf format string is incorrect.  It should be
"/usr/lib/sendmail %s"

0
 
jlevieCommented:
sprintf(sendmail_path, "/usr/lib/sendmail &s", mail_to);

Should be:

sprintf(sendmail_path, "/usr/lib/sendmail %s", mail_to);

Also, there's an extraneous % in "fprintf(mail,"Subject: %sError Notification\n");"

The code otherwise works using a test case of:

#include <stdio.h>

main()
{
  char *mail_to="sombody@somewhere.net";
  char *mail_from="sombody@somewhere.net";
  char *message="A test...\n";
  char sendmail_path[40];
  FILE *mail;
 
  sprintf(sendmail_path, "/usr/lib/sendmail %s", mail_to);
  mail = popen(sendmail_path,"w");
  fprintf(mail,"Reply-to: %s\n",mail_from);
  fprintf(mail,"From: %s\n",mail_from);
  fprintf(mail,"To: %s\n",mail_to);
  fprintf(mail,"Subject: Error Notification\n");
  fprintf(mail,"MIME-Version: 1.0\n");
  fprintf(mail,"Content-Type: text/html\n\n");
  fprintf(mail,"%s",message);
  fprintf(mail,"\r\n");
  pclose(mail);
}
0
 
xenia27Author Commented:
Question,

I try to put "\n" in my message string but I didn't see the message change lines as I desired...what's wrong?  How can I change lines?


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
xenia27Author Commented:
how can I put multiple email account??  Using ";"??
0
 
xenia27Author Commented:
why there are some particular email account I try to send the warning email through my program will not receive the warning message? but when I send a simple email by myself, and the account can receive the email??
0
 
xenia27Author Commented:
OK...now I got this error message...
it said "<root@localhost.localdomain>...Real domain name required for sender address"  Does this mean there is some setting wrong in the Linux...or something wrong in my program?  I do put a real email address for the sender part...but not sure why it takes <root@localhost.localdomain> for the sender address...Help please~~~~~
0
 
jlevieCommented:
> I try to put "\n" in my message string but I didn't see the message change lines

Since I can't see how you constructed the message I can't say what went wrong. But in my test example above if I do:

char *message="Line one...\nLine two...";

I see two lines in the body of the message when it is received.

> why there are some particular email account I try to send the warning email through my program
> will not receive the warning message?

What user are you when the program is run? It may matter in that some mail servers may reject mail whose sender is root, apache, web, http, etc. And it is the Envelope Sender that matters, not what's in the From header. You can set the Envelope Sender by using:

sprintf(sendmail_path, "/usr/lib/sendmail -f %s %s", mail_from, mail_to);

>  OK...now I got this error message...

See above.
0
 
xenia27Author Commented:
OK...this works but still I cannot send to some email account which is not in LAN...
Here is my error message...
--iB27ZT2Q002994.1101972929/localhost.localdomain
Content-Type: message/rfc822
Return-Path: <MAILER-DAEMON>
Received: from localhost (localhost)
by localhost.localdomain (8.12.8/8.12.8) id iB27ZT2P002994;
Thu, 2 Dec 2004 15:35:29 +0800
Date: Thu, 2 Dec 2004 15:35:29 +0800
From: Mail Delivery Subsystem <MAILER-DAEMON>
Message-Id: <200412020735.iB27ZT2P002994@localhost.localdomain>
To: <acuta_gui@10.10.1.3>
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="iB27ZT2P002994.1101972929/localhost.localdomain"
Subject: Returned mail: see transcript for details
Auto-Submitted: auto-generated (failure)
This is a MIME-encapsulated message
--iB27ZT2P002994.1101972929/localhost.localdomain
The original message was received at Thu, 2 Dec 2004 15:35:28 +0800
from localhost [127.0.0.1] (may be forged)
----- The following addresses had permanent fatal errors -----
<hanavivi@so-net.net.tw>
(reason: 553 Sorry, Please use domain name instead of IP.)
----- Transcript of session follows -----
... while talking to mail.so-net.net.tw.:
>>> MAIL From:<acuta_gui@10.10.1.3> SIZE=791
<<< 553 Sorry, Please use domain name instead of IP.
501 5.6.0 Data format error
--iB27ZT2P002994.1101972929/localhost.localdomain
Content-Type: message/delivery-status
Reporting-MTA: dns; localhost.localdomain
Received-From-MTA: DNS; localhost
Arrival-Date: Thu, 2 Dec 2004 15:35:28 +0800
Final-Recipient: RFC822; hanavivi@so-net.net.tw
Action: failed
Status: 5.1.3
Diagnostic-Code: SMTP; 553 Sorry, Please use domain name instead of IP.
Last-Attempt-Date: Thu, 2 Dec 2004 15:35:28 +0800
--iB27ZT2P002994.1101972929/localhost.localdomain
Content-Type: message/rfc822
Return-Path: <acuta_gui@10.10.1.3>
Received: from localhost.localdomain (localhost [127.0.0.1] (may be forged))
by localhost.localdomain (8.12.8/8.12.8) with ESMTP id iB27ZR2P002992
for <hanavivi@so-net.net.tw>; Thu, 2 Dec 2004 15:35:28 +0800
Received: (from root@localhost)
by localhost.localdomain (8.12.8/8.12.8/Submit) id iB27ZQYe002990
for hanavivi@so-net.net.tw; Thu, 2 Dec 2004 15:35:26 +0800
Date: Thu, 2 Dec 2004 15:35:26 +0800
Message-Id: <200412020735.iB27ZQYe002990@localhost.localdomain>
Reply-to: acuta_gui@10.10.1.3
From: acuta_gui@10.10.1.3
To: hanavivi@so-net.net.tw

//////////////////////////////////////////////////////////////////////////////////////////
what's wrong with my setting?
0
 
jlevieCommented:
MAIL From:<acuta_gui@10.10.1.3> is where the problem is. That remote MTA will only accept mail from senders with valid addresses. Change mail_from in your program to a real address and it should work.
0
 
xenia27Author Commented:
Great...this is exactly where my problem is...now I am finally able to send the mails..however, my message is still without any "\n"...they only lineup not form into several lines...what's wrong?

here is how i assemble my messages...

char *msg;
sprintf(msg, "------------------------------------\n");
sprintf(msg, "%s          Message Sender          \n", msg);
sprintf(msg, "Time: \t%s\n", msg, time);

then, I do this
fprintf(mail,message);

but what I see is...
------------------------------------          Message Sender          Time:               xx:xx:xx (some time format)

what would be wrong?
0
 
jlevieCommented:
I just realized that you include:

Content-Type: text/html

as a header, but don't actually format the body as multi-part. Since this is just a text message leave that header and "MIME-Version: 1.0" out and I think you'll find that it line breaks as it should.

0
 
xenia27Author Commented:
OK...I'm trying to remove "html" part now.
BUT...I got another problem....

Reporting-MTA: dns; localhost.localdomain
Arrival-Date: Fri, 3 Dec 2004 14:01:24 +0800

Final-Recipient: RFC822; acuta-support.tid.co.jp@localhost.localdomain
Action: failed
Status: 5.1.1
Remote-MTA: DNS; [127.0.0.1]
Diagnostic-Code: SMTP; 550 5.1.1 <acuta-support.tid.co.jp@localhost.localdomain>... User unknown
Last-Attempt-Date: Fri, 3 Dec 2004 14:01:36 +0800

Reporting-MTA: dns; cyrus43.tid.co.jp
Arrival-Date: Fri,  3 Dec 2004 15:00:57 +0900 (JST)

Final-Recipient: rfc822; kaikawa@tid.co.jp
Action: failed
Status: 5.0.0
Diagnostic-Code: X-Postfix; host localhost.tid.co.jp[127.0.0.1] said:
    550-Mailbox unknown.  Either there is no mailbox associated with this
    550-name or you do not have authorization to see it. 550 5.1.1 User unknown
    (in reply to RCPT TO command)


Got this two messages...what's wrong? >"<
0
 
jlevieCommented:
acuta-support.tid.co.jp@localhost.localdomain is a problem... And that's probably as a result of the basic machine configuration where it does not have a recodnized Fully Qualified Domain Name (FQDN) as evidenced by Reporting-MTA: dns; localhost.localdomain
0
 
xenia27Author Commented:
so how can I solve this problem?  What kinda setting I need to change?
0
 
jlevieCommented:
That is simply a matter of configuring your Linux box to have a valid FQDN as it's hostname and then making sure that the hosts file is in one of the two forms below:

# Hosts file for a machine with a static IP
127.0.0.1   localhost.localdomain localhost
123.4.56    this-system.this-domain.tld this-system

# Hosts file for a machine with a dynamic IP
127.0.0.1   this-system.this-domain.tld this-system localhost.localdomain localhost
0
 
xenia27Author Commented:
Great~  It works now...^^...Thanks for your helps~~~
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now