What if the smtp server of my Email account needs authentication?

Following is a simple program for sending Email in a GUI without username and password.But I found that my smtp server needs authentication,so i can't send mail.Who can help me with this problem?i'll be very grateful.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class SMTPClient extends JFrame {
private JButton sendButton = new JButton("Send Message");
private JLabel fromLabel = new JLabel("From: ");
private JLabel toLabel = new JLabel("To: ");
private JLabel hostLabel = new JLabel("SMTP Server: ");
private JLabel subjectLabel = new JLabel("Subject: ");
private JTextField fromField = new JTextField(40);
private JTextField toField = new JTextField(40);
private JTextField hostField = new JTextField(40);
private JTextField subjectField = new JTextField(40);
private JTextArea message = new JTextArea(40, 72);
private JScrollPane jsp = new JScrollPane(message);
public SMTPClient() {
super("SMTP Client");
Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel labels = new JPanel();
labels.setLayout(new GridLayout(4, 1));
labels.add(hostLabel);
JPanel fields = new JPanel();
fields.setLayout(new GridLayout(4, 1));
String host = System.getProperty("mail.host", "");
hostField.setText(host);
fields.add(hostField);
labels.add(toLabel);
fields.add(toField);
String from = System.getProperty("mail.from", "");
fromField.setText(from);
labels.add(fromLabel);
fields.add(fromField);
labels.add(subjectLabel);
fields.add(subjectField);
Box north = Box.createHorizontalBox();
north.add(labels);
north.add(fields);
contentPane.add(north, BorderLayout.NORTH);
message.setFont(new Font("Monospaced", Font.PLAIN, 12));
contentPane.add(jsp, BorderLayout.CENTER);
JPanel south = new JPanel();
south.setLayout(new FlowLayout(FlowLayout.CENTER));
south.add(sendButton);
sendButton.addActionListener(new SendAction());
contentPane.add(south, BorderLayout.SOUTH);
this.pack();
class SendAction implements ActionListener {
public void actionPerformed(ActionEvent evt) {
try {
Properties props = new Properties();
props.put("mail.host", hostField.getText());
Session mailConnection = Session.getInstance(props, null);
final Message msg = new MimeMessage(mailConnection);
Address to = new InternetAddress(toField.getText());
Address from = new InternetAddress(fromField.getText());
msg.setContent(message.getText(), "text/plain");
msg.setFrom(from);
msg.setRecipient(Message.RecipientType.TO, to);
msg.setSubject(subjectField.getText());
// This can take a non-trivial amount of time so
// spawn a thread to handle it.
Runnable r = new Runnable() {
public void run() {
try {
Transport.send(msg);
catch (Exception ex) {
ex.printStackTrace();
Thread t = new Thread(r);
t.start();
message.setText("");
catch (Exception ex) {
// I should really bring up a more specific error dialog here.
ex.printStackTrace();
public static void main(String[] args) {
SMTPClient client = new SMTPClient();
// Next line requires Java 1.3 or later. I want to set up the
// exit behavior here rather than in the constructor since
// other programs that use this class may not want to exit
// the application when the SMTPClient window closes.
client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
client.show();
}

The answer is in the javadocs for the com.sun.mail.smtp package:
http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html

Similar Messages

  • Can I change the smtp server with Yahoo push account?

    My yahoo email account will send and receive over EDGE using the default yahoo mail settings. On my home Cox internet WiFi network I can retrieve messages but cannot send. When sending it says it was sent and makes the "swooshing" mail sent sound, but the message disappears. It does not appear in the "sent" folder or "drafts" folder either. No error message is returned.
    I suspect this is related to Cox blocking the smtp server, but the iPhone does not allow me to change the smtp settings on the default yahoo account. Does anyone know how to do this? I can set it up manually for POP access, but then I'm flooded with spam.

    No, you cannot change the SMTP server on the Yahoo push account.
    Yahoo push only works if you configure your account using the Yahoo! Mail shortcut on the iPhone, and that shortcut does not allow for ANY customization.

  • WHAT ARE THE  SETTINGS FOR AN ICLOUD EMAIL ACCOUNT

    I am trying to create an iCloud email account on my iPad with IOS 6.0.1
    what are the settings for Host name in incoming and outgoing mail servers?

    the information on that link doesnt work.  my icloud address is [email protected] not [email protected].. although i tried both on my galaxy note 2.  either way the server information is not verifying. 

  • TS3899 What is the outgoing server for my ymail account?

    I am trying to set up my email (ymail account) on my iPhone 4s but  I am unsure what to put as the outgoing mail server...

    You would need to contact the email provider for that information.

  • How to find out about the SMTP Server

    Hi,
    I have been trying to configure groupware in the portal - in particular I want to enable the sending of emails through the portal. I already have a how-to-guide that that seems to explain the steps quite well. However, it mentions that I need to know the SMTP Server of the email. Can you tell me how to find out about the SMTP Server? Where do I need to look for the name of it?
    Thank you and regards,
    Katharina

    Hi Katharina,
    you need the SMTP server of your company. This means you can't look for it in the portal, but have to ask the responsible person in your company.
    Kind regards,
    dominik

  • Can not specify the SMTP server port, username and password for my SharePoint 2013 web application

    We have our SMTP server under port number 141 and we should add username and password. but inside SharePoint 2013, I can only define the SMTP server name , from email, reply-to . But there are not fields to define the port number , the username and password.
    So can anyone advice from where I can define the port number and other field settings for the SMTP server ?
    Thanks

    i am no sure about user name and password. i never saw that option.
    check this guide:
    http://blogs.technet.com/b/tirumals/archive/2012/03/17/step-by-step-configuration-of-outgoing-emails-from-sharepoint-to-microsoft-online.aspx
    http://blog.fpweb.net/configuring-an-smtp-server-for-sharepoint/#.UuANoxAo6M8
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog
    thanks for the reply, but in our case the SMTP is  a separate server , and to connect to it i need to define the ; server IP /Name , port number, username & password. but in SharePoint there is no option to define the port number , and the links you
    provide are regarding configuring SMTP server, while we already have an SMTP server but i need to connect SP with it . can you advice please?

  • I can't send email from my iPad. I am from Australia but on holidays in Greece. Does anyone know what is the smtp outserver for Greece that I should use?

    I can't send email from my iPad. I am from Australia but on holidays in Greece. Does anyone know what is the smtp outserver for Greece that I should use?

    As you haven't told us who your email provider is, no.
    There isn't an SMTP server for Greece - it is either provided by your email provider, or the Internet provider you are connected through.

  • Why is Mail asking me for the name of an smtp server for an email address that doesn't exist?

    I've migrated from Snow Leopard to Mountain Lion on a new Mac, but in trying to use Mail on ML, it keeps asking me for the name of an smtp server for an email address that's never existed. The addy has my user name correct, but the server part of the address doesn't exist, or at least I've never used an email address with that provider. On ML there's no plist file for Mail, so nothing to delete there. What else can I do to get Mail working? The only other option I have is to abandon Mail as being crippled and useless, and use Postbox, which for it's price (US$9.95) is an attractive option. OTOH, I've paid for Mail after all, so it really ought to work. Any clues as to what I can do to stop its nonsensical behaviour? How do I file a bug report?
    TIA.
    Pauline

    Amasis wrote:
    On ML there's no plist file for Mail, so nothing to delete there.
    ~/Library/Containers/com.apple.mail/Container.plist
    (Go to your Finder "Go" menu hold the option key to choose "Library", since the ~/Library is hidden on ML)

  • TS3899 what is the outgoing server port for smtp

    what is the outgoing server port for smtp

    Google is your friend for searching for SMTP configuration for your Email provider
    25 is blocked by most providers (because of spam)
    465 and 587 are the ports used by authenticated SMTP setups.

  • IMAC: What is the SMTP outgoing mail server?

    IMAC: What is the SMTP outgoing mail server?

    You need to get that information from your internet service provider if you are using an email address provided by them or, if you are only using iCloud, then the info can be found here:
    http://support.apple.com/kb/HT4864
    FWIW, in order to set up email, you need both an incoming and outgoing server address (in addition to your email address/user name and password). Those are the servers your email program uses when sending or receiving emails.

  • Email Enabled lists - where to run the SMTP server? On APP server or on Exchange Server? Or somewhere else?

    Hi there,
    I need to setup EMail Enabled lists in SharePoint 2010 site. Where do I need to run the SMTP server? On APP server or on Exchange Server? Or somewhere else?
    Thank you so much.

    The SMTP service cannot run on the Exchange server. You can run it on a SharePoint server, or a stand alone server and share out the drop directory over SMB.
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • I have set up a new email account however it is unable to connect to the smtp server as it seems to be offline - how do i take the smtp server online?

    I have set up a new email account however it is unable to connect to the smtp server as it seems to be offline - how do i take the smtp server online?

    the smtp server is the property of the mail provider and running in their server room
    talk to them
    and make sure the ports required by the mail providers smtp server are not blocked by your firewall or by your router or by your isp

  • What is the smtp incoming mail server for iCloud?

    What is the smtp incoming mail server for iCloud?

    There is no such thing as an "SMTP incoming mail server." You set up iCloud mail by checking the box marked Mail in the iCloud preference pane. You don't need to know the addresses of the servers.

  • I changed my password on my aol account but it did not change on the SMTP server which is preventing me from answering email.  Help

    I changed my aol password but the SMTP server password did not change so I can't send mail.  How can I change the SMTP password?

    Go into Settings > Mail, Contacts, Calendars and select the account, then tap the account on the popup that you should get, and then tap on the SMTP server name

  • The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

     try
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress("[email protected]");
                    mail.To.Add("[email protected]");
                    mail.Subject = "Test Mail..!!!!";
                    mail.Body = "mail with attachment";
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(@"C:\Attachment.txt");
                    mail.Attachments.Add(attachment);
                    SmtpServer.Port = 587;
                    SmtpServer.UseDefaultCredentials = true;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("userid", "Password");
                    SmtpServer.EnableSsl = true;
                    SmtpServer.Send(mail);
    Catch(Exception exception)
    When i m run this part of code it throw an Ecxeption                                                          
            Given Below is the Error.. 
        The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
    Bikky Kumar

     try
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress("[email protected]");
                    mail.To.Add("[email protected]");
                    mail.Subject = "Test Mail..!!!!";
                    mail.Body = "mail with attachment";
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(@"C:\Attachment.txt");
                    mail.Attachments.Add(attachment);
                    SmtpServer.Port = 587;
    SmtpServer.UseDefaultCredentials = true;    ///Set it to false, or remove this line
                    SmtpServer.Credentials = new System.Net.NetworkCredential("userid", "Password");
                    SmtpServer.EnableSsl = true;
                    SmtpServer.Send(mail);
    Catch(Exception exception)
    Given Below is the Error..      The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
    Solution:
    The error might occur due to following cases.
    case 1: when the password is wrong
    case 2: when you try to login from some App
    case 3: when you try to login from the domain other than your time zone/domain/computer (This
    is the case in most of scenarios when sending mail from code)
    There is a solution for each
    solution for case 1: Enter the correct password.
    Recomended: solution for case 2: go to
    security settings at the following link https://www.google.com/settings/security/lesssecureapps and
    enable less secure apps . So that you will be able to login from all apps.
    solution 1 for case 3: (This might be helpful) you need to review the activity. but reviewing the activity will not be helpful due to latest security
    standards the link will not be useful. So try the below case.
    solution 2 for case 3: If you have hosted your code somewhere on production server and if you have access to the production server, than take remote
    desktop connection to the production server and try to login once from the browser of the production server. This will add exception for login to google and you will be allowed to login from code.
    But what if you don't have access to the production server. try
    the solution 3
    solution 3 for case 3: You have to enable
    login from other timezone / ip for your google account.
    to do this follow the link https://g.co/allowaccess and
    allow access by clicking the continue button.
    And that's it. Here you go. Now you will be able to login from any of the computer and by any means of app to your google account.
    Regards,
    Nabeel Arif

Maybe you are looking for

  • BackUp plan/the finder can't copy files

    I am trying to backup some files manually from one hd to another, and everytime i do this i get this error message : The finder cannot complete the operation because some data in "any file.psd" could not be read or written. (Error code -36) what i fo

  • List of Non-thread safe system calls in Solaris 2.6??

    Hi, I'm searching for a list of system calls which are known to be non thread safe in a multithreaded process in Solaris 2.6. Anyone know of such a list?

  • Possible Sleep or Time Machine Problem - Please Read

    I am using Leopard by the way. I accidentally put my mac into sleep mode and after it came back on all of my hard drive space was gone. I had like 50 gigs or so before and now I it is showing around 7 gigs. I am assuming there was a swap file or such

  • Fail Updating Document Using DI API in Form_Data_Update_Event

    Hi, B1 2007B PL14 I have problem updating document using DI API in Form_data_Update_Event. I have made sure that beforeaction=false and actionsuccess=true (to me, this means that B1 has completed the update process), then my codes will be executed to

  • Muse and typekit

    Hi all I have a subscrption for CC I use Typekit to integrate "special" fonts in my sites Muse This service is great but I ask the following question: What will happen if I decide not to take the Adobe CC subscription anymore ? Is that all  my existi