Sending Mass Mailers Using Office 365
I've been working in Microsoft Online Services Technical Support for the last 18 months, and one question I get from customers is, ""How do you use the SMTP server for Office 365?". We still support the predecessor to Office 365, Business Productivity Online Services (BPOS), so we also get the question, "How do you use the SMTP server for BPOS?". I've explained this process over the phone, a lot, but customers always manage to bungle it up unless I go online with them and walk them through the process, but a lot of customers refuse. Most of the time I think the customers are afraid I'll learn some deep dark secret from their company, so they'd rather pay for some expensive software package that does what could be setup in a few minutes. So Here's what you do:
(1) Log into the Microsoft Online Portal (MOP), at
https://portal.microsoftonline.com
(2) Click on the "Outlook" link (it's at the top of the web page)
(3) Click on the dropdown that's on the right side of the label that says "options"
(4) Click on "See All Options"
(5) Click on "Settings for POP, IMAP and SMTP access..."
A window pops up that says "Protocol Settings" at the top of it. This page tells
you all the settings you need for POP, IMAP and SMTP access (just like it says on
the link in step (5)). Here's what it says on my computer:
SMTP setting | |
|
As you can see, the name of the SMTP server is presented right there. You also need to use port 587 and TLS encryption. That' really all there is to it. You can use these values in Outlook (you'll need to use the POP settings for receiving e-mail, but this article is about sending e-mail) for sending individual e-mails, or you can use them in a mass mailing program, too. Here's a program that I wrote in Java for mass mailing. Besides the Java SDK, you'll also need the JavaMail API:
import java.io.*; import javax.mail.*; import javax.mail.internet.*; import java.security.Security; import java.util.Properties; class MassMailer { public static void main(String[] args) throws Exception { //define a string for assigning to addresses to. String to_addr = "dave@community-info.org"; //this will be updated by values in a file //open up file that stores to addresses FileInputStream fstream = new FileInputStream(args[0]); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); //open up file that stores the message text - this can be plain text or html FileInputStream msgStream = new FileInputStream(args[1]); DataInputStream msgIn = new DataInputStream(msgStream); BufferedReader msgBR = new BufferedReader(new InputStreamReader(msgIn)); //create text string to send String text = ""; String msgTxt = ""; while ((msgTxt = msgBR.readLine()) != null) { text += msgTxt; } Properties props = new Properties(); props.setProperty("mail.transport.protocol", "smtp"); props.setProperty("mail.host", "pod51010.outlook.com"); //note, this is the server name I found above - use your own props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "587"); props.put("mail.debug", "false"); props.put("mail.smtp.socketFactory.port", "587"); props.put("mail.smtp.socketFactory.fallback", "false"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("Your e-mail address", "Your password"); } } ); while ((to_addr = br.readLine()) != null) { Transport transport = session.getTransport(); InternetAddress addressFrom = new InternetAddress("Your e-mail address"); //note, if this isn't the same as e-mail address you used //in the authentication step, you'll be thrown into the spam folder MimeMessage message = new MimeMessage(session); message.setSender(addressFrom); message.setSubject("Your Subject Line"); message.setContent(text, "text/html"); // this can also be text/plain message.setFrom(new InternetAddress("Your e-mail address", "Your friendly name")); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to_addr)); transport.connect(); System.out.println("Just added e-mail address " + to_addr); // I like to see the program progress transport.send(message); transport.close(); } } }