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.
Related
I have a busy CentOS webserver that sends a lot of outbound email using PHPMailer. Postfix and Sendmail are both installed on it, but as there are no user accounts that use the server for email, I wonder if I can uninstall both of those and close ports 25,110,465,587 for security. Will PHPMailer still be able to send outgoing?
No, PHPMailer (and any other mail library for any programming language, for that matter) is just an interface for the email service and not a mailer daemon by itself.
You do not need POP (you can shut that down anytime) but you will need sendmail or some other SMTP service to actually do the work PHP Mailer requests.
If you definitely need to shut down sendmail and the related ports, you can always part ways with it and implement your mail delivery logic using Mailgun, SendGrid, Elastic Email, Pepipost or some other alternative. There WILL be coding involved as you'll need to interact with those providers' APIs and they all involve some costs (Mailgun and Sendgrid have free tiers for a couple thousand emails per month, I don't remember if the others do as well) and integration efforts.
I believe you should be fine to remove any local mail service as PHPMailer is made to use an external service. You can close those ports as it's only outgoing!
The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.
https://github.com/PHPMailer/PHPMailer
Indeed you do not need to have a local mail server, however, if it's really busy, sending via a local mail server will be far more efficient than sending via any external service, especially if these messages are being sent immediately (and synchronously) in response to HTTP requests. You can see more about this in the PHPMailer wiki on github.
You definitely don't need POP3, but you may need inbound on port 25 if you're going to receive/handle bounces from the messages you send and want them to come back to you.
In this scenario you would only need port 25 open in both directions, none of the others.
Also, be clear what you mean by sendmail. Postfix is a complete mail server and so is sendmail, but the name sendmail is also often used to refer the sendmail binary that is actually a local message submission agent - it's what gets used by the PHP mail() function. postfix provides a sendmail binary, but postfix is not sendmail.
I'm building a Hapi app and I want to implement basic user email confirmation feature. I'm a bit lost as I don't have prior experience on mail servers nor have I implemented mailing feature to any apps. I do NOT want to use external mail service such as Google for sending the emails. There is also no need to be able to receive email nor store the sent messages. I want the emails be sent from address 'mailerbot#mydomain.com', where I already have a running web app in mydomain.com. The server is a Centos 7 running in EC2.
Do I have to setup own mail server (Haraka, Postfix, etc.) or can I send email directly to the users from my Node.js app (Nodemailer, Hapi Mailer, etc.), without using neither local nor remote mail server? I looked at some examples, but they usually use Google or such for sending the mail, so I'm not sure how to achieve exactly what I want, i.e. simple mail confirmation messages sent from Node.js app.
Node.js does not have a built-in SMTP server, and you must have an SMTP server of some kind to send email.
It is possible to run your own SMTP server with Node.js (https://github.com/andris9/smtp-server) and then use Nodemailer or Hapi Mailer with it.
Try using this : https://github.com/paullang/hapi-mail
This is a plugin built especially for hapi.
I want to send emails with my Node server. These are no-reply type emails, simply as reminders. The server will not need to handle incoming email. I know that there are services out there like Postmark, Mailchimp, etc. that will send emails for me, but I really do not want to pay for a service.
Using Nodemailer I have to specify a SMTP server. I can piggy back off of GMail or something but that's not desirable because the mail will not be coming from my domain (correct?).
But there is also node-sendmail which will send email without an SMTP server. Can someone describe the implications of sending email without an SMTP server? Dropped connections? No indication if message is undeliverable?
What are the implications of running my own SMTP server? Does it open up additional security holes? Can you recommend an open source SMTP server that requires minimal setup and maintenance?
Have a look at Haraka. It's an easy to use SMTP server that should do exactly what you're looking for. It's currently in use by Craigslist, so you know it's solid.
There's a section in the docs on how to set it up for sending mail - very last section 6.1.
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'm developing a website on an XP virtual machine and have an SMTP virtual server set up in IIS -- it delivers mail just fine. What I would like is to confirm that any emails the site sends are only going to a specific domain.
The XP firewall seems to only involve incoming connections, I can't block outgoing TCP on port 25. And I haven't been able to configure the SMTP server to filter by delivery address.
With this setup, is there any easy way to filter outgoing email by destination address?
Here's one idea:
Under Advanced Delivery options (SMTP Virtual Server Properties > Delivery tab > Advanced). There you can set a "Smart Host" which is the SMTP server that will be used to actually send the mail, so you could possibly have it deliver directly to the specific domain's incoming SMTP server.
I think the easiest way would be to add a check to your mail sending code on the website (there's got to be some class which is in charge of sending the mails out).
You could include a check which is only active when the code is compiled in debug mode (using compiler directives). Thus, when you are developing and building the site in debug mode, this code checks if the outgoing messages are valid (specific domain) or not. If they are it lets them go, else it doesn't send the mail.