ruidi
ruidi

Reputation: 11

Email using localhost's port 25?

My site is hosted on a shared Linux server and I wrote a C function using sockets to send myself emails. The emails are sent without problems as long as I send them to myself. Emails to myself are sent without username and password. But if I send them to gmail, etc. they get rejected because they complain about localhost.

This is what I currently do:

  1. Use socket() to open port 25 on localhost.
  2. write / read from socket for the following:

HELO localhost
MAIL FROM: [email protected]
RCPT TO: [email protected]
DATA
blahblah
QUIT

Upvotes: 1

Views: 245

Answers (2)

jweyrich
jweyrich

Reputation: 32260

What is happening is that the destination server performs a reverse DNS lookup to determine whether the domain name is associated with the IP of your SMTP server.

For example, if you send an email as [email protected], the destination server will perform a reverse DNS lookup to determine if the IP of your server is associated with (resolves to) example.com.

I suggest reading about Forward-confirmed reverse DNS.

Upvotes: 0

Hasturkun
Hasturkun

Reputation: 36412

You really should be sending your host name, rather than localhost. Many servers will reject messages with nonsensical hosts, messages from servers that are not associated with the envelope domain, and from servers that exist in one of the many DNSRBLs.

Local policy may also be prohibiting mail relaying, you might need to ask your hosting provider for an appropriate mail relay.

Inter server message delivery does not generally require authentication.

You may want to consider using a library such as libsmtp to handle the protocol details.

Upvotes: 1

Related Questions