473,659 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error with mail progmming

dmjpro
2,476 Top Contributor
i have no problem while i complile the program.
this is my source code ......

Expand|Select|Wrap|Line Numbers
  1. import javax.mail.*;
  2. import javax.mail.internet.*;
  3. import java.util.*;
  4.  
  5. class MailTest1
  6. {
  7.         public static void main(String args[])
  8.         {
  9.                try
  10.                    {
  11.                         if(args.length == 0)
  12.                         {
  13.                                 throw new Exception("Insufficient arguments ....");
  14.                         }
  15.                          String smtpServer=args[0];
  16.                          String to=args[1];
  17.                          String from=args[2];
  18.                          String subject=args[3];
  19.                          String body=args[4];
  20.                          send(smtpServer, to, from, subject, body);
  21.                    }
  22.                    catch (Exception ex)
  23.                                       {
  24.                         System.out.println("Exception in main: " + ex.getMessage());
  25.                    }
  26.         }
  27.         public static void send(String smtpServer, String to, String from
  28.            , String subject, String body)
  29.         {
  30.                 try
  31.                 {
  32.                         Properties props = System.getProperties();
  33.                         // -- Attaching to default Session, or we could start
  34.                         props.put("mail.smtp.host", smtpServer);
  35.                         Session session = Session.getDefaultInstance(props, nu
  36.                         // -- Create a new message --
  37.                         Message msg = new MimeMessage(session);
  38.                         // -- Set the FROM and TO fields --
  39.                         msg.setFrom(new InternetAddress(from));
  40.                         msg.setRecipients(Message.RecipientType.TO,
  41.                                                 InternetAddress.parse(to, false));
  42.                         // -- We could include CC recipients too --
  43.                         // if (cc != null)
  44.                         // msg.setRecipients(Message.RecipientType.CC
  45.                         // ,InternetAddress.parse(cc, false));
  46.                         // -- Set the subject and body text --
  47.                         msg.setSubject(subject);
  48.                         msg.setText(body);
  49.                         // -- Set some other header information --
  50.                         msg.setHeader("X-Mailer", "LOTONtechEmail");
  51.                         msg.setSentDate(new Date());
  52.                         // -- Send the message --
  53.                         Transport.send(msg);
  54.                         System.out.println("Message sent OK.");
  55.                 }
  56.                 catch (Exception ex)
  57.                 {
  58.                         System.out.println("Exception in send: " + ex.getMessage());
  59.                 }
  60.         }
  61. }
  62.  
but when i run the program then i get an error ......

Exception in thread "main" java.lang.NoCla ssDefFoundError : javax/mail/Message

plz help...
it's urgent

kind regards,
dmjpro.
Jun 13 '07 #1
6 1371
JosAH
11,448 Recognized Expert MVP
That package is supposed to be an extension so you should put that .jar in
the 'ext' directory under the lib directory of your JRE.

kind regards,

Jos
Jun 13 '07 #2
dmjpro
2,476 Top Contributor
That package is supposed to be an extension so you should put that .jar in
the 'ext' directory under the lib directory of your JRE.

kind regards,

Jos
then why didn't i get the compiling error?
plz explain.

kind regards,
dmjpro.
Jun 13 '07 #3
dmjpro
2,476 Top Contributor
then why didn't i get the compiling error?
plz explain.

kind regards,
dmjpro.

Ok i solved it.
but i have a new problem .. how can i get host name for a mail server... sayGMAIL server?
plz help.

kind regards,
Dmjpro.
Jun 13 '07 #4
JosAH
11,448 Recognized Expert MVP
Ok i solved it.
but i have a new problem .. how can i get host name for a mail server... sayGMAIL server?
plz help.

kind regards,
Dmjpro.
You can't; your program has to "know" it in advance. There is no service that
gives you a list of smtp servers anywhere in the world.

kind regards,

Jos
Jun 13 '07 #5
dmjpro
2,476 Top Contributor
You can't; your program has to "know" it in advance. There is no service that
gives you a list of smtp servers anywhere in the world.

kind regards,

Jos

so do u know those server names for common use mail serveres????
plzzz say...

kind regards,
dmjpro.
Jun 13 '07 #6
JosAH
11,448 Recognized Expert MVP
so do u know those server names for common use mail serveres????
plzzz say...

kind regards,
dmjpro.
I only know the name of the smtp server supplied by my ISP.

kind regards,

Jos
Jun 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3278
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that I believe if it's solved, the remaining stuff is easy... my full program until now is here: http://www.geocities.com/tom4_h4wk/progmail.zip the problem is the segmentation fault when main trys to run leficheiro.c.... the *.c2 files are the...
1
3092
by: jam | last post by:
Dear All, I am writing a console and it send a email out when it hits error it calls this static void SendErrorEmail(string error) { System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(); System.Web.Mail.SmtpMail.SmtpServer = smtpServer;
0
2528
by: Erwan | last post by:
I have a strange (but very blocking) result when using the smtpmail class from an ASPX page : here is the (very simple !) code... '-------------------------------------------------- mail.To = "el@illico.fr" mail.From = "el@illico.fr" mail.Subject = "test envoi de mail" mail.Body = "test envoi de mail"
9
3215
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on CDOmail. I don't want to use the Outlook reference because outlook prompts each time program access it and I have found a way to disable that. Can I use webmail with exchange? Thanks
5
2491
by: Nathan Sokalski | last post by:
I am attempting to send an email using ASP.NET 1.1's Mail.SmtpMail.Send() method. My code contains all of the following: Dim mailmsg As New Mail.MailMessage Mail.SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings("smtpserver") mailmsg.BodyFormat = Mail.MailFormat.Text mailmsg.Subject = "My Subject"
2
12168
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used, error is thrown at the .send point. Error is: The following error occured Sending an email: System.ApplicationException: An error occurred sending an email To helen@HerMail.com From ade@MyMail.com Cc Subject A test with Finlistener #1. The body...
2
6817
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how to fix this error. I am able to send messages sometimes both other times randomly following error appear EXCEPTION:
6
26358
by: Dave Kelly | last post by:
Sorry for the long post, it is easier to discard information than to have to wait for it to arrive. So here goes: This code worked perfectly when I was an Earthlink customer. Sprint decided not to pardner with Earthlink and create their own IP. Since then everything email has been broke. Sprint/Embarq is the only copper wire DSL provider where I live.
10
6960
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration of section c. Not sure where went wrong as the web page displayed internal server error. Also, what is the error 543? and error 2114. Where to find the list of errors in websites as it is not the standard apache error. I could not find...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.