DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: argggggh

  1. #1
    Join Date
    Nov 2003
    Posts
    13

    argggggh

    please can u help me lads. I have made this simple email client and i want to add validation to the Senders email address and the recipients email address. can ne 1 tell me how to do this. Here is the code i have so far below of the email classes


    [CODE]
    import java.util.*;
    class SimpleEmail {

    private String sender;
    private String sendermail;
    private String recipient;
    private String recipientmail;

    private String subject;
    private String content;

    private String messageID; // unique id for email
    private String returnPath; // a return Email if fails
    private String org; //company name
    private String mime; //version if encoded
    private String mailer; //name of mail client used
    private String contentType; //text/plain charset= US-ascii

    private Date dateOfEmail;

    public SimpleEmail(String s,String sm, String r,String rm,String mi,String rp,String o, String mm, String ml, String ct,String t, String c, Date d) {

    sender = s;
    sendermail = sm;
    recipient = r;
    recipientmail = rm;

    messageID = mi;
    returnPath = rp;
    org = o;
    mime = mm;
    mailer = ml;
    contentType = ct;


    subject = t;
    content= c;

    dateOfEmail = d;
    }

    public void setSender(String s) {
    sender = s;
    if ( sender == " ")
    sender = "unknown";
    }
    public String getSender() {
    return sender;
    }



    public void setSenderMail(String sm) {
    sendermail = sm;
    if ( sendermail == " ")
    sendermail = "unknown";
    }
    public String getSenderMail() {
    return sendermail;
    }



    public void setRecipient(String r) {
    recipient = r;
    if ( recipient == " ")
    recipient = "unknown";
    }
    public String getRecipient() {
    return recipient;
    }



    public void setRecipientMail(String rm) {
    recipientmail = rm;
    if ( recipient == " ")
    recipientmail = "unknown";
    }
    public String getRecipientMail() {
    return recipientmail;
    }



    public void setMessageId(String mi) {
    messageID = mi;
    if ( messageID == " ")
    messageID = "unknown";
    }
    public String getMessageId() {
    return messageID;
    }




    public void setReturnPath(String rp) {
    returnPath = rp;
    if ( returnPath == " ")
    returnPath = "unknown";
    }
    public String getReturnPath() {
    return returnPath;
    }



    public void setOrg(String o) {
    org = o;
    if ( org == " ")
    org = "unknown";
    }
    public String getOrg() {
    return org;
    }



    public void setMime(String mm) {
    mime = mm;
    if ( mime == " ")
    mime = "unknown";
    }
    public String getMime() {
    return mime;
    }



    public void setMailer(String ml) {
    mailer = ml;
    if ( mailer == " ")
    mailer = "unknown";
    }
    public String getMailer() {
    return mailer;
    }



    public void setcontentType(String ct) {
    contentType = ct;
    if ( contentType == " ")
    contentType = "unknown";
    }
    public String getcontentType() {
    return contentType;
    }



    public void setSubject(String t) {
    subject = t;
    if ( subject == " ")
    subject = "unknown";

    }
    public String getSubject() {
    return subject;
    }

    public void setContent(String c) {
    content = c;
    if ( content == " ")
    content = "unknown";
    }
    public String getContent() {
    return content;
    }

    public void setDate(Date d) {
    dateOfEmail = d;
    }
    public Date getDate() {
    return dateOfEmail;
    }




    }





    Code:
    import java.util.*;
    public class SimpleEmailTest
    {
    
    
    public static final String notKnown = "Unknown";
    public static void main( String[] args )
    {
    SimpleEmail email; // email object to test.
    String whoFromName; // sender
    String fromMail;// sender email address
    String whoToName; // recipient
    String toMail;// recipients email address
    String messageID; // unique id for email
    String returnPath; // a return Email if fails
    String org; //company name
    String mime; //version if encoded
    String mailer; //name of mail client used
    String contentType; //text/plain charset= US-ascii
    String subject; // subject matter
    String content; // text content of email
    
    Date recieved = new Date();
    
    email = new SimpleEmail( notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, notKnown, recieved );
    
    
    
    
    email.setSender( "Suresh" );
    email.setSenderMail("SureshDutt@hotmail.com");
    
    email.setRecipient( "Sheena Receiver" );
    email.setRecipientMail("SheenaReciever@hotmail.com");
    
    email.setMessageId("12212.4224.3443.3");
    email.setReturnPath("admin@hotmail.com");
    email.setOrg("Dutt Independant Traders(DITS)");
    email.setMime("Verseion 1");
    email.setMailer("outlook express");
    email.setcontentType("text charset= US-ASCII");
    
    
    email.setSubject( "How are you today?" );
    email.setContent( "I just wrote an email class!" );
    
    System.out.println( "SimpleEmail: " +
    "\n From: " + email.getSender() + email.getSenderMail() +
    "\n To: " + email.getRecipient() + email.getRecipientMail() +
    "\n Subject: " + email.getSubject() +
    "\n Message ID: " + email.getMessageId() +
    "\n Return Path: " + email.getReturnPath() +
    "\n Organisation: " + email.getOrg() +
    "\n MIME: " + email.getMime() +
    "\n Mailer: " + email.getMailer() +
    "\n Content Type: " + email.getcontentType() +
    "\n Date: " +
    email.getDate().toString() +
    "\n Message: " + email.getContent() + "\n");
    
    
    
    }
    }
    [ArchAngel added CODE tags]

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    Do you meant that you just want to validate whether a String forms a valid e-mail address? If so, just use a regular expression.
    ArchAngel.
    O:-)

  3. #3
    Join Date
    Nov 2003
    Posts
    13
    i woul dlike to know whether it forms a valid email address. eg it has a @ sign etc

  4. #4
    Join Date
    Mar 2003
    Posts
    834
    Like I said - use a regular expression. If you only want to be sure the String has an '@' symbol you can use the String's indexOf(...) method.
    ArchAngel.
    O:-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links