Carven
Carven

Reputation: 15660

Resolving the actual email address in SMTP

I have a socket setup in Java and the user could input their user ID and password to log into the mail's SMTP server. When sending out the email, I need to know the user's email address on the server so that I can put it into the From: header of the email. But sometimes, the user's ID may not be exactly the same as the address of his email. For eg, the user ID could be abc_john and the host name could be smtp.smith.com but the actual email address could be [email protected]. Something like that. That's the user name does not imply its actual email address.

Is there a way to resolve for its actual email address in Java? I am connecting tot he SMTP server using Socket, not the JavaMail API. I am hoping if there could be a SMTP command that could return the actual email address.

Upvotes: 0

Views: 1310

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596673

Send the SMTP server a VRFY command specifying the username as a parameter. If the server supports VRFY (it is an optional but recommended command), the response should include the full email address of the user's mailbox. Refer to RFC 2821 for more details.

Upvotes: 2

Mark Rotteveel
Mark Rotteveel

Reputation: 109034

No you cannot derive anything based on the username and SMTP server used. A single SMTP server can serve as the MX for a multitude of domains (for example my company use gmail as its mail provider, but our emailaddress are simply from our company-domain). And in the past (before the rise of spam), you could use - at least in theory - any SMTP server to send mail for any given e-mailaddress.

Simply put: the user will need to provide the full e-mailaddress, one way or another.

Upvotes: 0

Related Questions