How to catch invalid emails & How to send to multiple emails

This is a long two-part question.
Part One:
I would like to catch invalid emails within the JavaMail code and send the valid emails. I am using the following code to do this. The problem I am running into is when there is a valid email, sometimes it will be caught within the code without being sent and it will show up as a validunsentemail. I have set sendpartial to true, so this shouldn't be happening. Also, is there a way to check if a domain name is in existence before sending the email?
Part Two:
For testing purposes, I would like to mix valid and invalid emails for TO, but I don't know how to send to more than one email using an array. I have looked at other posting on the forum of how to do this, but I keep getting errors when I try other's suggestions. Maybe somebody will be able to help with this problem if they see the code below.
Thanks in advance for all your help!
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.event.*;
import javax.activation.*;
public class Practice
public static void main (String[] args) {
Transport trans = null;
try {
Properties props = System.getProperties();
props.put("mail.smtp.host", "hostname");
props.put("mail.smtp.sendpartial","true");
Session mailConnection = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailConnection);
Address angela= new InternetAddress("[email protected]");
InternetAddress[] address ={new InternetAddress("[email protected]")};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setContent("This is a test. This is only a test. What's Next?", "text/plain");
msg.setFrom(angela);
msg.setSubject("Testing 123");
msg.setSentDate(new Date());
msg.saveChanges();
trans = mailConnection.getTransport(address[0]);
trans.connect();
trans.send(msg, address);
System.out.println("Mail was sent successfully.");
try {Thread.sleep(5);}catch(InterruptedException e){}
} catch (MessagingException mex){
try {Thread.sleep(5);}catch(InterruptedException e){}
mex.printStackTrace();
System.out.println();
Exception ex = mex;
do{
if (ex instanceof SendFailedException){
SendFailedException sfex = (SendFailedException) ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null){
System.out.println(" ** Invalid Addresses");
if (invalid != null) {
for (int i=0; i< invalid.length; i++)
System.out.println(" " + invalid);
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null){
System.out.println(" ** ValidUnsent Addresses");
if (validUnsent !=null){
for (int i=0; i<validUnsent.length; i++)
System.out.println(" "+validUnsent[i]);
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null){
System.out.println(" **ValidSent Addresses");
if (validSent != null){
for (int i=0; i<validSent.length; i++)
System.out.println(" "+validSent[i]);
System.out.println();
if (ex instanceof MessagingException)
ex = ((MessagingException)ex).getNextException();
else
ex = null;
} while (ex != null);
} finally {
try {
trans.close();
} catch (MessagingException mex){  /*  ignore */}

I am working on exactly the same problem. What you need to do is use the destination mail server to send mails. For example: address
[email protected] is an invalid user.
Using normal way you wont be able to catch invalid mail box error.
If you use mail server of jabcreative.com to send email then you will get an unknown user exception.
To find mail server of jabcreative.com you will have to do MX LookUp on DNS entry
Have a look at this URL
http://www.cee.hw.ac.uk/courses/5nn2/3/12.htm

Similar Messages

  • Cannot catch invalid email addresses

    Hi,
    I have been using this very normal email sending routine but for some reason even if the email address is invalid (ex abc), the Transport.send() method does not throw any exception and continues.
    Does anyone know why this should happen??
    The code is given below
         for (int i = 0; i < p.length; i++){
    uEmail = p.getUserEmail();
    System.out.println("Sending Email to :" + uEmail);
         emailContent = emailString;
    /***************** SENDING THE EMAILS *************************/
    try {
              Properties props = System.getProperties();
    //System.out.println("Using mail server"+mailserveraddress);
              props.put("mail.smtp.host",mailserveraddress);
              Session session = Session.getDefaultInstance(props, null);
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("[email protected]"));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(uEmail));
    message.setSubject("Homeland Headlines " + dateString);
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(emailContent);
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    //System.out.println("Setting the content");
    message.setContent(multipart);
              //System.out.println("NO exception till here");
    // Send the message
    Transport.send(message);
              System.out.println("Email Sent successfully");
    catch(SendFailedException me) {
              System.out.println("Email not sent to :" + uEmail);
              System.out.println("The exception is" +me.toString());
              invalidemails.add(uEmail);
              catch(MessagingException mesex){
              System.out.println("The exception is:"+mesex.toString());
              sentemailflag="false";
              catch(Exception e){
                   System.out.println("Unexpected error is:"+ e.toString());
                   sentemailflag="false";
    The control never reaches any of the exception blocks even though p has some invalid email addresses.
    It prints:
    Sending email to: abc
    Email sent successfully
    Thanks,
    Chetan

    Hi,
    I believe I have answered this question quite a few times in this forum.
    There is no standard way to know if the e-mail id exists or not, SMTP standards does not mandate the server implementors to notify this.
    There are several things that can happen:
    a. The server implements the VRFY command -- Then you know immediately if the account is active.
    b. The server does not implement the VRFY command, but if the acount does not exist tells you when you send the RCPT command.
    c. The server does not tell you till you say QUIT.
    d. The server accepts the mail silently and sends a mail later saying that the mailbox does not exist.
    Since there is no sure-shot way of determining this no exception is thrown.
    (Also check out the RFC for a typical SMTP session if the commands confuse you.)
    cheers
    Projyal

  • "Invalid address" only when sending to multiple addresses

    I can send an email to <username>@gmail.com and to <username>@mac.com, but if I try to send an email to both recipients at once, my mail server says "Invalid address" even though my colleague can send an email to those addresses without a problem.
    Since my colleague can do it, it can't be the server; but I can't figure out the difference between my Mail configuration and his.
    Any ideas?

    I found my own answer. I didn't have password authentication on for the outgoing server. Weird. I was able to send mail to individuals without a password, but couldn't send to multiple people.
    It's working now.

  • How to send to multiple people using same port?

    I am trying to have one person send TWO audio sources to 10 others using same port- lets say 12345. I get "Can't open local data port:" error. The first audio is fine since I just use .addTarget(). Is there a way i can do the same for the 2nd audio source still using the same port? thanks!

    As far as I know, you should transmit using even-numbered ports, eg. 22222 and 22224.
    I think a port numbered 22223 and 22225 are opened respectively to handle control information.
    Could be wrong, but try it anyway!
    StHogan

  • How to send a multiple-p​age fax from HP 8615?

    I frequently need to fax a double-sided document, and would like to have both sides arrive as one document.  (The fax recipient is an online fax service which forwards the fax as a PDF to a distribution list.)  With other multi-function units, I would be asked if I wanted to add an additional page after the first one was scanned.  The new HP8615 I just bought doesn't display this prompt - whether the first side of the page is scanned through the ADF or on the glass, as soon as the first page is scanned, the fax is sent.  The recipient has to assemble multiple PDFs into one file.
    Any suggestions?  I do not want to copy the back side of the form just so I can stack both pages into the ADF.  I'd rather not scan the form, front and back, to a file on the computer and then fax from there, either.
    Thanks!

    Thanks for the answer.  It wasn't what I hoped to hear, certainly, but thanks for confirming what I suspected.  It should have occurred to me to research this before buying this product.  It's great otherwise!

  • Set up apple Id with invalid email so can't validate new account. How can I edit account  info when I can't sign in for anything? Thx

    Set up apple Id with invalid email so can't validate new account. How can I edit account  info when I can't sign in for anything? Thx

    Hi Franklin777,
    If you are having issues with your Apple ID, this article will get you started.
    Frequently asked questions about Apple ID
    The first step is to find and edit the Apple ID you created:
    Apple ID: Finding your Apple ID
    If you need to reset your security questions this article will help ... 
    The rescue email address is a different address than the one you use for your Apple ID. 
    Rescue email address and how to reset Apple ID security questions
    You can edit or delete your rescue email address at My Apple ID. To edit your rescue email address:
    Navigate to My Apple ID using your web browser.
    Click "Manage your account"
    When prompted, sign in using your Apple ID and password.
    Click Password & Security
    You'll be asked to answer 2 of your 3 security questions before you can make any modifications. If you are unable to remember your answers, you can choose to send an email to your rescue email to reset your security questions.
    Hope you get back on track soon!
    - Judy

  • I've tried to sign into the eprint center and it says invalid email. How do I correct this

    I have an HP OfficeJet 6700. I can't sign into eprint center because it says invalid email.
    I know the email address for the printer but I want to change it. Can you walk me thru this?
    gayle
    This question was solved.
    View Solution.

    If you are trying to create an account and it is saying invalid email or email already in use, it means that you have a snapfish account. In that situation, you will want to go to http://www.snapfish.com/ and click the login button in the top right hand corner of the page. When it prompts you to enter your email address and password, click the "Forgot your password?" link and enter your email address. They will send you a email with a temporary password and a link to change the password. After you change the password, go back to http://www.eprintcenter.com/ and log in with your email address and the password you just created. 
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • How to sending email from Oracle Forms

    How to sending email from Oracle 6i(Forms)
    I need to send email to a distribution list(multiple email addresses).

    send email of multiple email address
    [email protected],[email protected],[email protected]
    create or replace function mailout
    (sender in varchar2,
    recipient in varchar2,
    ccrecipient in varchar2,
    subject in varchar2,
    message in varchar2) return number
    is
    crlf varchar2(2) := chr(13)||chr(10);
    connection utl_smtp.connection;
    mailhost varchar2(50) := 'Add email server Ip Address here';
    header varchar2(4000);
    v_num number :=1;
    str number:=0;
    email varchar2(50);
    begin
    connection := utl_smtp.open_connection(mailhost,25);
    header := 'Date: '||to_char(sysdate,'dd mon yy hh24:mi:ss')||crlf||
    'From: '||sender||' '||crlf||
    'Subject: '||subject||crlf||
    'To: '||recipient||crlf||
    'Cc: '||ccrecipient||crlf||message;
    utl_smtp.helo(connection,mailhost);
    utl_smtp.mail(connection,sender);
    utl_smtp.rcpt(connection,recipient);
    while (instr(ccrecipient,',',1,v_num)>0) loop
    email:=substr(ccrecipient,str+1,instr(ccrecipient,',',1,v_num)-str-1);
    dbms_output.put_line(email);
    utl_smtp.rcpt(connection,email);
    str:=instr(ccrecipient,',',1,v_num);
    v_num:=v_num+1;
    end loop;
    utl_smtp.open_data(connection);
    -- utl_smtp.write_data(connection,header);
    utl_smtp.write_data(connection,'MIME-Version:1.0'||crlf||'Content-type:text/html'||crlf||header);
    utl_smtp.close_data(connection);
    utl_smtp.quit(connection);
    return 0;
    exception
    when utl_smtp.invalid_operation then
    dbms_output.put_line('Invalid Operation in SMTP transaction');
    return 1;
    when utl_smtp.transient_error then
    dbms_output.put_line('Temporary problem with sending email ');
    return 2;
    when utl_smtp.permanent_error then
    dbms_output.put_line('Permanent problem with sending email ');
    return 3;
    end;

  • How to send custom email asynchronously?

    Hi All,
    I am using code to send custom email like:
    SmtpClient smtpClient = new SmtpClient(smtpServer);
    NetworkCredential oCredential = new NetworkCredential("", "");
    try
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = oCredential;
    smtpClient.Send(mailMessage);
    catch (Exception)
    This code working fine but how to send email asynchronously?
    Thanks in advance!

    Hi Steve & Amit,
    Thanks for you reply, Here is my complete code:
    public static void Sendmail(string To, string subject, string Body, string frommail)
    string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
    string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress;
    string smtpReplyTo = SPAdministrationWebApplication.Local.OutboundMailReplyToAddress;
    MailMessage mailMessage = new MailMessage();
    System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress(frommail, "My Intranet");
    mailMessage.From = from;
    mailMessage.To.Add(new MailAddress(To));
    mailMessage.Subject = subject;
    mailMessage.IsBodyHtml = true;
    mailMessage.Priority = MailPriority.High;
    mailMessage.Body = "<html><body>" + Body + "<br><br>With Regards,<br><b>My Intranet</b></body></html>";
    SmtpClient smtpClient = new SmtpClient(smtpServer);
    NetworkCredential oCredential = new NetworkCredential("", "");
    try
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = oCredential;
    smtpClient.Send(mailMessage);
    catch (Exception)
    Could you please suggest me how to implement you solution, thanks!

  • [SOLVED]How to send email to a local user?

    I have installed Mutt, msmtp, procmail and I can send and receive emails to/from remote hosts and I'd like to send email locally also (to the recipients on the same machine as the sender).
    When I try to send email to a local user from the root account -
    echo "Test message" | mail -s "Test subject" localuser
    then I get an error that connection to the port 25 is refused. Because the /etc/msmtprc file contains the 'localhost' as the default account's host, and on the local host I don't have a mail server listening on 25 port running.
    When I try to send email from a non-root account which has in /$HOME/.msmtprc file a real email account on a remote server, then of course there is an error that the domain for the email address 'localuser' is not recognized.
    How can sending email to local users be enabled?
    Last edited by nbd (2014-09-30 22:33:37)

    If I understand correctly, postfix it's a constantly running daemon. Seems to be an overhead for delivering only from time to time sent messages.
    ewaller wrote:
    > Out of the box, sendmail should be safe, but I think you have to enable local mail.
    Currently I have msmtp-mta installed, which is described as having sendmail functionality. If I install sendmail - will it be possible to send local email without running email daemons?

  • OBIEE 11g: How to send email from Analysis (via Action Framework)

    Hi,
    I have installed OBIEE 11g SampleAppLite in my POC box.
    One of the features I want to have is to allow users to send their feedback (email) about a report to the report owner. Can this be done without launching Outlook? I tried to Invoke a Browser Script and found that I can display a form showing Recipient, Subject and Message text fields, but I do not know how to send the email.
    Thanks!

    Hi Devarasu,
    Thanks for your reply. The link you gave is for sending iBots. But if I do this, users will not be able to send their feedback / comment.

  • How to send as an email the spool request?

    Dear Experts,
    My last post was Email background schedule report to gmail or yahoo mail .
    I got solution but it's work as a notification which we can say the after report run it triggers mail that report is completed as this time.
    But i required the thing how to send a spool request of a report  as an email attachment.
    it will be in .xls or .pdf or xyz format.
    It was the additional task which was required by my organization.
    I also want to know the following things.
    1. what is sap default configuration and system behind it.
    2. what the things abaper have to check.
    3. what is bcs_examples & where do i found these bcs_example8.
    Please guide me to explore my knowledge.
    Thanks & regards
    Nayan Lad
    Note for moderator : Sir, I will close request at 2:30 pm today onward, so please do not lock it.
    Moderator Message: All your questions can be answered by searching.
    Edited by: kishan P on Nov 13, 2010 3:29 PM

    need solution..

  • How to send email if job fails?

    I'm wondering how to send an email if a data load fails.  Or, do the same, if a Select > Into or Insert > Select  . . . or whatever . . . fails. Last week I set up a process to send an email using SQL Server express. 
    http://www.sqlservercentral.com/blogs/querying-microsoft-sql-server/2013/09/02/sending-mail-using-sql-server-express-edition/
    I can easily include a simple script at the end of a SQL statement:
    exec
    msdb.dbo.sp_send_dbmail
    So, if I run a Select, or whatever, I can run the exec and send an email.  Now, I'm trying to think about how to send an email if a process fails.  I don't think you can do it with a simple Select. 
    Any ideas, anyone?
    Thanks.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    This is a good read to understand on error handling in SQL
    http://www.sommarskog.se/error_handling_2005.html
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to send timer job email to "assigned to" feild value in a task list?

    Hi All,
    How to send timer job email  to "assigned to" field value in a task list if due date is after two days from now?

    Create a SharePoint Designer Workflow and use "pause until date" option when an new item is created/update.
    Using Server Object model, I believe you can create the timer job from item event receiver.
    --Cheers

  • I have forgotten my password for icloud, have an invalid email address and do not know my security answers. How can I transfer all my data from my old iphone to the new one?

    I have forgotten my password for icloud, have an invalid email address and do not know my security answers. How can I transfer all my data from my old iphone to the new one?

    In this case you won't be able to do that?

Maybe you are looking for