малоли, мб комуто понадобится
Код:
package ru.skyb.scripts.global.MailNotice;
import java.util.Vector;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.*;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.activation.FileDataSource;
import bitel.billing.server.util.MailMsg;
import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase;
import ru.bitel.bgbilling.server.util.Setup;
import ru.bitel.common.sql.ConnectionSet;
public class AttachmentFile
extends GlobalScriptBase
{
@Override
public void execute( Setup setup1, ConnectionSet connectionSet2 )
throws Exception
{
MailMsg msg = new MailMsg( setup1 );
MimeBodyPart htmlPart = new MimeBodyPart();
Vector objects = new Vector();
objects.addElement("mail@billing.com");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("hi");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String fileAttachment = "file.txt";//file name for attachment
DataSource source = new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("billing.csv");
multipart.addBodyPart(messageBodyPart);
// Put parts in message
htmlPart.setContent(multipart);
// Send the message
msg.sendMessage(objects, "subjeсt", multipart);
System.out.println("Msg Send ....") ;
}
}
да, я ещё от сюда библиотечку качал
Код:
http://www.java2s.com/Code/JarDownload/javax/javax.activation.jar.zip
_________________
Код:
Клиент: вер. 6.2.714 / 25.05.2015 17:27:15
os: Linux; java: Java HotSpot(TM) 64-Bit Server VM, v.1.8.0_45
Сервер: вер. 6.2.881 / 22.05.2015 17:56:55
os: Linux; java: Java HotSpot(TM) 64-Bit Server VM, v.1.8.0_45
Помощь по администрированию bgbilling в jabber конференции или Группа в telegramСтиль программирования - пьяный мастерстер
Разработка мобильных приложений