I am trying to write a fake SMTP server in nodejs, I just need use it to send notify email, but not receive email.
I have taken a look at node-smtp, but it just implements the protocol from client to SMTP server, it does not implement how to send mail from a SMTP server to another SMTP server.
If I know how one SMTP server send mail to another SMTP server, I think I can send mail without a SMTP server.
but it just implements the protocol from client to SMTP server, it does not implement how to send mail from a SMTP server to another SMTP server.
An SMTP server that can send mail also acts as an SMTP client. Not that you're trying to write an SMTP server anyway:
I just need use it to send notify email, but not receive email.
aka
I just need to write an SMTP client
Well in short it works this way: server-sender reads domain of recipient and is checking DNS for MX record for that domain (you can read it like - "hey DNS tell me please which server holds mails for that domain). Then it connects to remote SMTP and gives the messaage.
The dialogue could look like this:
client: HELLO server
server: 250 hello client, nice to meet you
client: MAIL FROM: tmg
server: 250 ok
client: RCPT TO: guilin
server: 250 ok
client: data
server: 354 Enter message, ending with "." on a line by itself
client: From: tmg
client: To: guilin
client: Subject: just a mail
client:
client: message body
client: .
server: 250 ok
client: quit
server: good bye
Did you look at Marak's node_mailer?
https://github.com/Marak/node_mailer
I have a fork of it, and another one, on my github site, for gmail smtp support
http://github.com/deitch
I use https://github.com/andris9/simplesmtp, it is actually a framework for creating SMTP servers/clients, however it is quite a good fit for testing.
There is also https://github.com/deitch/smtp-tester specially designed for testing, however I haven't used it.
Related
I am using PHPMailer to connect to a remote smtp server running Exim.
In my exim logs, I can see that the sending failed, but PHPMailer does not catch an exception and it seems like the SMTP server is returning an "Ok" status.
Here is the excerpt from my exim log:
2019-06-27 17:03:00 1hgbXj-0000O5-Vl == *******#gmail.com R=dnslookup T=remote_smtp defer (-44) H=alt4.gmail-smtp-in.l.google.com [108.177.119.27]: SMTP error from remote mail server after RCPT TO:<********#gmail.com>: 452-4.2.2 The email account that you tried to reach is over quota. Please direct\n452-4.2.2 the recipient to\n452 4.2.2 https://support.google.com/mail/?p=OverQuotaTemp **** - gsmtp
And here is the (end of the) PHPMailer debug output:
SERVER -> CLIENT: 250 OK id=1hgbf8-0008CL-15
CLIENT -> SERVER: RSET
SERVER -> CLIENT: 250 Reset OK
Done #0.0734977722168s
CLIENT -> SERVER: QUIT
Any way I can see this error in PHP so that I can log the error in my application?
This is nothing to do with PHPMailer. The PHPMailer debug output shows a successful delivery to your exim server. That's where its involvement ends - at no point does PHPMailer talk to gmail, and so never sees this response.
Exim (as intended) then goes on to try to deliver the message, but receives a failure notice from gmail. What you should then see in your logs is an attempt by exim to bounce the message to the return path, which is set by your mail server from the SMTP envelope sender used to submit the original message. You can control this address by setting the Sender property in PHPMailer, though it defaults to your from address, which is what you'd usually want.
If you want to hear about these bounces in your code instead of your mailbox, you need to get exim to pipe them to a script rather than a mailbox, and this is something that exim is quite happy to do.
Bounce handling is not a pleasant thing to write, but you may find that using VERP addressing helps.
Im using PHPmailer to send email if user enter his e-mail. But sometimes (1/2 of emails) i get an error:
2013-10-15 11:12:39 SERVER -> CLIENT: 555 sorry, too many emails (#5.7.1)
2013-10-15 11:12:39 SMTP ERROR: Password command failed: 555 sorry, too many emails (#5.7.1)
2013-10-15 11:12:39 CLIENT -> SERVER: QUIT
2013-10-15 11:12:39 SERVER -> CLIENT:
2013-10-15 11:12:39 SMTP ERROR: QUIT command failed:
SMTP connect() failed.
In one of my project I also experienced this error. You reached the limit of emails you're allowed to send for this mailserver (preventing its usage as spam server). You could implement a queue to spread sending the mails over a given time or you could try to find another mail server. Mail servers of Internet Providers usually have good sending rates.
I have a windows 2003 / IIS 6.5 machine running a classic ASP site.
The site itself sends emails ('forgot password', etc.) and I also run scripts on the machine to send email newsletters.
I don't have a real problem sending... but I am confused about how emailing actually works.
Is the SMTP server (IIS) ever communicating with my email provider (gmail for business) when I send from my website (I don't provide any login info)? Does my IIS SMTP server just blast emails out (maybe doing an MX lookup for the target?)? Is it the SPF record in the DNS records that allows this?
I just rebuilt our server (after disaster) and moved our email to gmail... so, I am setting this all up now... I can read all the 'how-to' articles - but unless I understand a few simple concepts, I won't really know what I am doing.
Thanks!
When sending a mail to someone, there's two SMTP servers involved.
Your own SMTP server (sender)
The recipients SMTP server (receiver)
Basically, when you send a mail from your mailclient, your mailclient sends the mail to your own SMTP server, which then sends the mail to the recipients SMTP server. The reason for this (hop) is because servers may be down/slow/etc and your own server's responsibility is now to try and deliver the mail for (usually) within 48 hours.
To find out what SMTP server the receipient has, the MX-records are looked up, by the sender SMTP, for the recipients domain:
C:\> nslookup -type=mx hotmail.com
Server: dns.server.com
Address: 183.255.245.11
Non-authoritative answer:
hotmail.com MX preference = 5, mail exchanger = mx1.hotmail.com
hotmail.com MX preference = 5, mail exchanger = mx2.hotmail.com
hotmail.com MX preference = 5, mail exchanger = mx3.hotmail.com
hotmail.com MX preference = 5, mail exchanger = mx4.hotmail.com
As you can see, multiple SMTP servers can be specified for a domain (for redundancy), and the sender SMTP will pick one based on priority (one that works). The mail is then sent to that server.
And (if not using a webmail) the recipients mailclient may download that mail using e.g. POP3 or IMAP protocols.
Now, when you send a mail from ASP.NET the sender SMTP server is usually the local IIS SMTP service, and not the usual SMTP server for your domain (the one that you yourself use to send mail; in your instance Gmail).
SPF-records are records added to your DNS to specify what SMTP servers are allowed to send mail from your domain. Usually, IF you specify them, the receiver SMTP servers force that the the sender SMTP server is listed in the SPF record for the domain in the from-address. If you don't specify them however, mail is usually let though anyway, and other SPAM-filers kick in.
Anyway, hope this helps to clarify things...
Out of the box, IIS 6 will send using the built in SMTP server, Classic ASP usually default to using the pickup directory x:\inetpub\mailroot\pickup\. ASP creates an email file in here and when the SMTP service detects it, the mail is moved for processing. If you stop the 'Simple Mail Transfer Protocol' service, you should see files backing up in here, starting it again will make them all go out.
The SMTP Virtual server will appear in IIS Management, and from there you can set it to use your google account as a forwarder, or better still, you should adjust your mail function to use SMTP to Google instead of local. Presuming that you are using CDOSYS, use the following code to specify a mail server and logon details:
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'This section provides the configuration information for the remote SMTP server.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yoursite.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail#yourserver.com"
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"
ObjSendMail.Configuration.Fields.Update
'End remote SMTP server configuration section==
ObjSendMail.To = "someone#someone.net"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "someone#someone.net"
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"
ObjSendMail.Send
Set ObjSendMail = Nothing
Source
You should monitor your mailroot folder from time to time, for the 'queue' and 'badmail' folders, even if the only action is to clear them out.
I am trying to create a small desktop app that sends out e-mails to people in the office (all internal). My application would run on a PC that is also on the network and the user will have outlook running for his own e-mails.
I'm looking at several examples where you need the SmtpClient and it needs to equal a host. Is there a way that I can just set it to use the local machine?
MailMessage mailObj = new MailMessage("admin#network.com",
reader["recipientAddress"].ToString(), "Subject", "Body");
SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
SMTPServer.Send(mailObj);
I read that 127.0.0.1 is the local machine. Would this work, or is there a different way of going about this?
Also would my messages go out if it sent a message to an external email?
You have to install a SMTP server on your localhost to be able to send mail.
Outlook only receives e-mails through POP3 or IMAP, etc.
edit:
i.e. you need
some server that accepts mail through SMTP from your client and forwards it to its destination; and
some server that accepts mail (normally through SMTP) and stores it in a mailbox, so people can retrieve them later through POP3 or IMAP or whatever means.
Your company mail server should normally do both.
edit2:
You might be able to cheat and use SMTPClient to deliver the mail to the receiver's mailbox server directly though.
Try resolving for the MX record (see How to get mx records for a dns name with System.Net.DNS?) and create a SMTPClient directly to the best MX server returned.
If Microsoft implemented enough of the SMTP specification and your host is not treated as sending spam, the mail should go through.
I am new to James Mail Server. I configured as the steps mentioned by James.
I can send send mails to internal network, but I am not able to send mails to external network like gmail.
Somebody please help me to resolve the issue
Thanks in advance
Rohith
Sorry for the late but it may help some people in the future.
If you want configure JAMES to send mails to external network you must edit the file conf.xml in the ${JAMES_DIR}/apps/james/SAR-INF.
Uncommented these line to define an SMTP relay server if necessary through the gateway:
<processor name="transport">
<mailet match="All" class="RemoteDelivery">
...
<gateway> smtp.gmail.com </gateway>
<gatewayPort>25</gatewayPort>
</mailet>
</processor>
Example to use the gmail relay server:
POP Server: pop.gmail.com (on activation of the POP option of GMail)
SMTP Server: smtp.gmail.com
IMAP Server: imap.gmail.com
EDIT: gmail requires an authentication so you must set the gatewayusername and the gatewayPassword markups:
<gatewayusername>login</gatewayusername>
<gatewayPassword>pass</gatewayPassword>
See http://mail.google.com/support/bin/answer.py?answer=10350