Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to send email from a C++ program.

I want to do it using sendmail. Well, actually I don't care how, I just found that none of the smtp libaries work...

The way to do this, I found via google, is this:

echo "This will go into the body of the mail." | mail -s "Subject line" you@youremailid.com

The problem is, the mail never arrives at destination. Now what I find peculiar: Shouldn't there be a need for a smtp-server URL? Such as smtp.my-provider.com:25 ?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Sendmail will try to look up the MX record of the domain you're sending to, so you wouldn't have to specify the SMTP server's address or hostname by default. If you do need to force a particular address, that can be handled via DNS or an entry in the Sendmail mailertable file.

You should first try to determine what happened to your original message. Try sending from your application and running:

tail -f /var/log/maillog

You can also view the mail queue directly by using the "mailq" command. If that command returns output, you can try to force the queue to be processed with "sendmail -v -q". That will reveal the nature of the error.

Also check the root user's email for bounce-back messages.

share|improve this answer
    
There was no such logfile. But mailq reveiled that a message was frozen. With exim -Mb and exim -Mh I was able to look at the header and message. exim -bp gave me the message ID and exim -Mrm <id> removed the message in question. –  Quandary Nov 14 '10 at 19:38

There's no need for an SMTP-server DNS name because the mail command expects to communicate with a local Mail Transport Agent (MTA) on the same machine. For Linux that MTA is often Sendmail. The sendmail configuration might include the DNS name of your ISP's mail-server (MTA) as a smarthost if you need to route outgoing mail through your ISP's mail-server.

I would check the mail logs to see what happened to your outboind mail. It might be queued for delivery and you might get a non-delivery report in due course.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.