[サンプルコード]
/*変換用文字列*/
var lng = GetLocaleInfo( "encoding" );
var org = GetLocaleInfo( "mail_encoding" );
/*インスタンス作成*/
var mm = new MailMessage;
var mh = mm.header;
/*マルチパート作成*/
var mp = new MultiPartMessage(mm);
var mpp = mp.createpart();
var mph = mpp.header;
/*メールヘッダ設定*/
var rt = new Runtime;
var user = rt.GetUserName()
mh.SetField("From", user + “@opst.co.jp”);
mh.SetField("To","appserver@opst.co.jp");
mh.SetField("Subject","upload");
mh.SetField("Content-Type","multipart/mixed; ");
mh.SetField("Content-Transfer-Encoding","7bit");
/*データファイル名の定義*/
var dataName = "business.xls";
/*マルチパートヘッダ設定*/
mph.setField("MIME-Version","1.0");
mph.setField("Content-Type","application/octet-stream");
mph.setField("Content-Transfer-Encoding","base64");
var nm = TextConverter.Convert( dataName, lng, org );
mph.setField("Content-Disposition", "attachment; filename=\"" + nm + "\"");
/*マルチパート内にデータを読み込む*/
var fs = new FileSystem;
var fp = fs.open(dataName, FileSystem.OPEN_READ);
mpp.writeString( Base64Encoder.Convert( fp.read() ) );
mp.freeze();
fp.Close();
/*メールヘッダにバウンダリを書き込む*/
mh.SetSubField("Content-Type","boundary=\"" + mp.boundary + "\"");
/*マルチパート全体をメールボディに書き込む*/
mm.write( mp.read() );
/*メール送信*/
var smtp1 = new Smtp;
try {
var res = smtp1.Connect("pop3server:25");
if ( res.Value == 0 ) {
throw new Exception("Connect",0,"Error");
}
var ret = smtp1.sendMail(mm);
if ( ret.Value == 0 ) {
throw new Exception("sendMail",0,"Error");
}
}
catch(e) {
MessageBox( e.message );
}
smtp1.Quit();
|