Прив Katy, ниже приведенный код думаю поможет
Код демонстрирует как отправлять маилики с аттачами используя SMTP компоненты
Code:
import com.jscape.inet.smtp.*;
import com.jscape.inet.mime.*;
import com.jscape.inet.email.*;
import java.io.*;
public class SmtpAttachmentExample extends SmtpAdapter {
public void sendMessage(String hostname, String to, String from, String subject, String body, String attachment) throws SmtpException,
IOException, MimeException {
// create new Smtp instance
Smtp smtp = new Smtp(hostname);
// enable debugging
smtp.setDebug(true);
// register this class to capture SMTP related events
smtp.addSmtpListener(this);
// connect to SMTP server
smtp.connect();
// create email message
EmailMessage email = new EmailMessage();
email.setTo(to);
email.setFrom(from);
email.setSubject(subject);
email.setBody(body);
// add attachment to email message
email.addAttachment(new Attachment(new File(attachment)));
// send email message
smtp.send(email);
// disconnect from SMTP server
smtp.disconnect();
}
// capture connect event
public void connected(SmtpConnectedEvent evt) {
System.out.println("Connected to SMTP server: " + evt.getHostname());
}
// capture disconnect event
public void disconnected(SmtpDisconnectedEvent evt) {
System.out.println("Disconnected from SMTP server: " + evt.getHostname());
}
public static void main(String[] args) {
String hostname;
String to;
String from;
String subject;
String body;
String attach;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter SMTP hostname (e.g. mail.domain.com): ");
hostname = reader.readLine();
System.out.print("Enter To address (e.g. [email protected]): ");
to = reader.readLine();
System.out.print("Enter From address (e.g. [email protected]): ");
from = reader.readLine();
subject = "iNet Factory Attachment Example";
body = "see attached image";
attach = "image.gif";
SmtpAttachmentExample example = new SmtpAttachmentExample();
example.sendMessage(hostname,to,from,subject,body,attach);
}
catch(Exception e) {
e.printStackTrace();
}
}
}