Which SMTP sever to send Java Mail to when the server is cloud-based? - java-8

Java 8 here, although this really is more of a generic Exchange/SMTP question I suppose.
I purchased a domain name and Office 365 support from GoDaddy, and as a result, have several email addresses through them. Let's say one of these is support#myapp.example.com.
I am writing a Java 8 app that will allow users to send emails to this support address (through the app). I will likely use the excellent Simple Java Mail library, which wraps the Java Mail API. And so somewhere in my app there will be some code that looks something like:
Email email = EmailBuilder.startingBlank()
.to("MyApp Help Desk", "support#myapp.example.com")
.withSubject("Support Ticket #12345")
.withPlainText("Something went wrong inside the MyApp!")
.buildEmail();
Mailer mailer = MailerBuilder
.withSMTPServer("smtp.host.com", 587, "user#host.com", "password")
.withTransportStrategy(TransportStrategy.SMTP_TLS)
.withProperty("mail.smtp.sendpartial", true)
.buildMailer();
mailer.sendMail(email);
Pretty straight-forward stuff, right? Except I'm confused about one simple thing: which SMTP server am I using here? Would I use the Microsoft Exchange server that my GoDaddy account provides me, or would I choose something else?

That depends a little bit on what you want to do.
If you just want to make one attempt to send the mail, you connect to the mail server that accepts mail for support#myapp.example.com. It sounds like this is an office365 server owned by Microsoft that accepts mail for myapp.example.com. There should be public DNS records for that domain. I haven't used the Simple Java Mail library, but from your pseudocode, I assume it does the DNS lookups for you.
It sometimes happens that an application encounters errors when trying to send an email. For example, somebody could restart your app server in the middle of the smtp conversation, or reboot your router, or something else. It's pretty common to use a Mail Transfer Agent (MTA) such as Exchange to help make this process more robust. If the MTA fails on the first delivery attempt, it will retry delivery for some configurable period of time. In your case, you could send the email to your Exchange server, and it would route the email to myapp.example.com.
(In this case, Exchange is sort of acting as a Mail Submission Agent (MSA), but that's kind of a nitpick.)
Hope this helps.

Related

Exchange server mail interceptor (connector/delivery agents/mailflow)

My basic requirement is that I need to create "something" that is capable of intercepting emails incoming/outgoing from our mail server. It cannot be an extension to mail clients. Currently we consider only exchange server. In my research I found below resources that seems to be helpful.
Mail flow and the transport
Delivery agents and Delivery Agent connectors
Transport agents
From these transport agents seems to be quite old. Now I can't figure out what's the best from the remaining options(Mail flow and the transport or Delivery agents and Delivery Agent connectors).
Whatever I develop should be able to read email get some statistics (using mail header(s), amount of attachments etc...) and store it into a custom database. Additionally add some custom headers to incoming/outgoing mails.
Can anyone point me to right direction? Should it be some kind of a service that I can install in Exchange server? (admin center->mail flow-> connectors). For example, can I write it in c# and host it like an assembly? or may be a web hook to a hosted service where Exchange will forward emails in real time etc...
I couldn't find any examples/tutorials except this
If its OnPrem Exchange and you don't have or are considering Office365 then Transport Agents would be the right thing to use. They haven't change since 2013 but are still what is used for this type of thing the last SDK was 2010 but its still valid given the lack of change on the backend https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd877026(v=exchg.140)
Delivery Agents are more for when you have an external gateway that you want to send and receive messages from.

Laravel 5.2 Mail cannot be sent outside domain

So when I try to send mails with Laravel's mail facade, I can only send within our company domain, when trying to send E-mails to either gmail or outlook, the mail never gets deliviered, but if I use outlook, the mail is delivered instantly.
I have turned everything upside down to figure out what it can be, but I cant find anything that cause this issue, not even a single trace of my app sending "non-internal" mails in the exchange logs.
Our company uses an Exchange 2003 server, I have checked the logs, no trace of (Out of company) mails are there
Im on a 20 hour streak, sorry for any confusion
/Tarre
The issue was that our Exchange SMTP relay didnt have the correct connectors and configuration.
To use exchange with SMTP.
Add a Connector bridge between your Exchange server and the Virtual SMTP server.
Configure "trusted" IP's.
Everything is done in the Exchange Server Management part.

How to send email alerts without SMTP server? [duplicate]

I have a .Net application. I want this application to send an email to me. How do I implement this without installing an SMTP server?
Using an SmtpClient to send a MailMessage does not require you to have a server on your local machine.
Your e-mail service provider is the one with the server (e.g. smtp.gmail.com), and your SmtpClient talks to it.
This article by Peter Bromberg on eggheadcafe.com
C# SMTP Mail without SMTP Service or CDO
explains how to send email without relying on an SMTP client:
Sending email via TCP using the native
SMTP RFC commands "HELO", "MAIL From",
RCPT TO", etc. is no big deal. That's
one of the first tricks we learn with
Telnet. Finding or writing managed
code that will do so reliably is
another story. The code in the class
that follows is not my original code -
I've cobbled it together from three
different sample sources, fixing
namespaces, error handling, and other
minor items, changing console code to
class library code, and providing a
complete Winforms - based test harness
front end that illustrates its correct
usage.
I've also included sample code
to correctly process and add a mail
attachment via an OpenFileDialog here.
This code MIME encodes and transmits
the attachment(s) according to the
specification.
You can't send email without the services of a SMTP server, there is of course no need for you to install one, just point your code at your ISPs SMTP server or your companies Exchange server (or what ever they use).

Pipe incoming email to a script on Windows IIS SMTP?

I have a web application running on Windows IIS. This app has a database where each item has a unique key (1, 2, 3...), and a list of email addresses (among other things).
I would like users to send email to the server, using an email address that identifies the item, then have the server relay the message to the email addresses for that item. For example, if a user sends email to the following address:
item-75#myserver.example.com
Then the server would receive the email and pipe it to a script. The script would query the database for item 75 to get a list of email addresses, then re-send the email.
I could do this easily on a unix system using sendmail, but I have no idea if a similar setup can be accomplished on a Windows system (or if it would require additional software).
(This sounds like you want to implement a feature like craigslist).
The IIS SMTP service can send email, and also accept email.
Here is what you want to do.
Configure your IIS SMTP service to accept emails for a domain (You can configure this in the properties of the IIS SMTP service, under domains). Say domain name "myserver.example.com"
Then, in your DNS server, configure a MX record that points to "myserver.example.com".
Now, when email gets sent to your IIS SMTP server, it will actually get placed in your mailroot/drop folder (you can also change this folder in the IIS SMTP Service properties).
Now that you are accepting email, the next step is to write a script that will:
1)Parse the emails.
2)Modify them accordingly (do you just want to change the "to" address?).
3)If you want to resend the emails, then you need to modify them accordingly.
You will need to add a single X-Sender header, that is used to identify the email address sending the email, and a X-Receiver header, for each recipient that is going to accept the email. Here is an example email that was modified:
X-Sender: me#mywebsite.com
X-Receiver: recip1#theirdomain.com
X-Receiver: recip2#theirdomain.com
From: "jim bob" <jim#example.com>
To: <item-75#myserver.example.com>
Subject: test
MIME-Version: 1.0
Content-Type: text/plain;
Message-ID: <024f01c9e130$b3eca500$0401a8c0#local>
test
Once you have this modified content, you will want to write it to a file in the mailroot/pickup directory. Be sure to use a unique name.
The IIS SMTP Service will come by, pickup the email, and relay it on, sending the email using the X-Sender as the MAIL FROM address, and sending it to each email address listed in each X-Receiver header.
4)Run this script as a scheduled task. Another option is to build it as a windows service, or to implement something like a filesystemwatcher, where it executes each time an email is created as a file.
5)Another option to all of this is to actually implement a SMTP Event Sink, but I think that is overkill for what you want to do, and can create more headaches, than it solves. I would only go the event sink route if I like pain.
Hopefully I didn't make that about as clear as mud.
Event Sinks aren't difficult at all! In fact, there are about a dozen examples written in VBS (which runs on a Win server using WSH) which accomplish exactly what you wish to do. The OnArrival event sink runs in REAL-TIME using any computer user account you wish w/o any security risk since the message is asynchronous and doesn't report back.
This is actually a terribly easy thing to do - one of the easiest. Once set up, it never breaks either. On one server I've had one running for more than 9 years processing a few thousand incoming messages per day! I've set up about a dozen of these things - if it takes you more than a couple hours, you're doing it very wrong. If it were any easier than this on UNIX, my grandmother could be a UNIX programmer so I wouldn't go bragging that this is easier to do on a UNIX server.
http://msdn.microsoft.com/en-us/library/ms528023.aspx
http://support.microsoft.com/kb/894286
http://msdn.microsoft.com/en-us/library/ms526206.aspx
http://msdn.microsoft.com/en-us/library/ms526620.aspx
You could read in email through POP3 or IMAP using a timed script. I'm also a UNIXer so I'm struggling to comprehend how something like this is so difficult, but there you have it. Here's what I reckon you should do.
Make a script in whatever language you like. As long as it can read from POP3 or IMAP.
Have Windows run the script every 5 minutes
Have the script access the mailbox and action any emails it needs to.
My personal preference would be to install Python, but if you're limited... I don't know. ASPNET isn't bad, but I've never used it for dirty-scripting before.

trouble sending mail with free smtp

I am trying to send mail from a local iis app using localhost as my smtp server after installing free smtp but I am getting the following error:
Mailbox unavailable. The server response was: Invalid
recipient: 'validAddress'#hotmail.com
Any idea what the problem could be?
it sounds like your free (3rd party) smtp app is not leaving your network and might be trying to see if it has that mailbox itself. Try and see if there is a setting to allow the smtp server to access external connections, etc. What is the name of the free smtp app, btw?
Alternatively, can u use the built in SMTP mail provider, built into iis? do you know how to use that, instead of this 3rd party app.
It looks more like the SMTP service needs to be configured to "Relay" email... Usually this involves telling it what YOUR mail domain is, and then any mail destin for a domain other than it's own will cause it to go out to the world, and try to relay the message to the real server.
But, be careful! This is how spammers exploit email servers. They look for SMTP listeners that will relay for them. You want to make sure yours will only accept relay mail from "localhost", or whatever machine will be connecting to it to do the sending.
A more secure way is to block port 25 inbound at your firewall to this box, so this SMTP server is not visible to the outside world.
Write and test a simple smtp sender in C. It needs 3 minutes with RFC
Use Wireshark to see what comes on the wire between your application and the SMTP server.

Resources