I use the following code to send mail.Text message sending is working fine but Mail with attachment is not working it gives the Exception.How to solve this
Try to define the exact path of your file, the mail.txt
.
For example if it is in C:
then go ahead and include the whole path like
String filename = ("c:\\users\\mail.txt");
and please note that sometime you might experience problems with ("c:\users\mail.txt")
which has single backslashes so to be safe just make them double backslashes
Also always make sure you use .printStackTrace()
method since it will help you identify where exactly your problem will be arising so that when you search on that problem you will be in good position to know exactly what you will be looking for.