html中if怎么设置,HTML中if怎么用?

回答:

发送HTML格式的邮件voID jButton8_actionPerFormed(ActionEvent e) {

try

{//此段代码用来发送带有HTML信息的邮件

Properties PRoPS = new Properties();

Authenticator Auth = new EmAIl_Autherticator();

PRoPS.put( "mAIl.smtp.host ",host);

PRoPS.put( "mAIl.smtp.Auth ", "true ");

Session session = Session.getDefAultInstance(PRoPS,Auth);

MimeMessage message = new MimeMessage(session);

//设置邮件正文

String HTMLtext= "

hello

"+ " click me please! ";

message.setContent(HTMLtext, "text/HTML ");//text/plAIn设置邮件的格式因为是带有HTML文档的,所以用text/HTML格式

message.setSubject(mAIl_SUbject);

// message.setText(mAIl_body);在使用message.setContent()时候,好象不能用message.setText()

message.setHeader(mAIl_head_name,mAIl_head_value);

message.setSentDate(new Date());

Address address = new InternetAddress(mAIl_from, "SUnxiaoming ");

message.setFrom(address);

Address toAddress = new InternetAddress(mAIl_to);

message.addRecipient(Message.RecipientType.TO,toAddress);

Transport.send(message);

System.out.PRintln( "send ok! ");

}

catch(Exception ex)

{

System.out.PRintln( "fAIld "+ex);

}

}

voID jButton9_actionPerFormed(ActionEvent e) {

try

{//此段代码用来发送带有图片的邮件

String file = "./20020423/test.gif ";

Properties PRoPS = new Properties();

Authenticator Auth = new EmAIl_Autherticator();

PRoPS.put( "mAIl.smtp.host ",host);

PRoPS.put( "mAIl.smtp.Auth ", "true ");

Session session = Session.getDefAultInstance(PRoPS,Auth);

MimeMessage message = new MimeMessage(session);

message.setSubject( "Embedded Image ");

Address address = new InternetAddress(mAIl_from, "SUnxiaoming ");

message.setFrom(address);

Address toAddress = new InternetAddress(mAIl_to);

message.addRecipient(Message.RecipientType.TO,toAddress);

message.setHeader(mAIl_head_name,mAIl_head_value);

message.setSentDate(new Date());

BodyPart messageBodyPart = new MimeBodyPart();

String HTMLText = "

"+ " %5C ";//加入图片

messageBodyPart.setContent(HTMLText, "text/HTML ");

//原理同发送附件一样,将邮件看成有多个部分组成的,先设置每一个部分,然后再全部将它们合起来即可。

//Create a related multi-part to combine the parts

MimeMultipart multipart = new MimeMultipart( "related ");

multipart.addBodyPart(messageBodyPart);

//Create part For the image

messageBodyPart = new MimeBodyPart();

//Fetch the image and associate to part

DataSource fds = new FileDataSource(file);

messageBodyPart.setDataHandler(new DataHandler(fds));

messageBodyPart.setHeader( "Content-ID ", "memememe ");

//Add part to multi-part

multipart.addBodyPart(messageBodyPart);

//Associate multi-part with message

message.setContent(multipart);

Transport.send(message);

System.out.PRintln( "send ok! ");

}

catch(Exception ex)

{

System.out.PRintln( "fAIld "+ex);

}

}

voID jButton7_actionPerFormed(ActionEvent e) {

try

{//该程序用来接受带有HTML信息的邮件

Properties PRoPS = System.getProperties();

Authenticator Auth = new EmAIl_Autherticator();

PRoPS.put( "mAIl.smtp.host ",host);

PRoPS.put( "mAIl.smtp.Auth ", "true ");

Session session = Session.getDefAultInstance(PRoPS,Auth);

Store store = session.getStore( "pop3 ");

store.connect(host,username,pasSWord);

//After connecting to the Store,you can get a Folder,which must be opened beFore you can read messages from it:

Folder folder = store.getFolder( "INBOX ");

folder.open(Folder.READ_WRITE);

Message message[] = folder.getMessages();

For (int i=0,n=message.length;i

// For (int i=0,n=1;i

{

String out_from_person = ((InternetAddress)message[i].getFrom()[0]).getPersonal();

String out_from_address = ((InternetAddress)message[i].getFrom()[0]).getAddress();

System.out.PRintln( "From: "+out_from_person+ "\t ");

System.out.PRintln( "Address: "+out_from_address+ "\t ");

String out_SUbject = message[i].getSubject();

System.out.PRintln( "Subject: "+out_SUbject+ "\t ");

//获取邮件的信息,并且对其每一部分进行操作

Part messagePart = message[i];

Object out_content = messagePart.getContent();

if (out_content instanceof Multipart)

{

messagePart = ((Multipart)out_content).getBodyPart(0);

System.out.PRintln( "[ Multipart Message ] ");

}

String out_content_type = messagePart.getContentType();

System.out.PRintln( "CONTENT: "+out_content_type);

jEditorPane1.setText( " ");//将其显示在jEditorPanel上

jEditorPane1.setContentType( "text/HTML ");

jEditorPane1.setText((String)out_content);

jEditorPane1.setEditable(false);

/*

if (out_content_type.startsWith( "text/plAIn ") || out_content_type.startsWith( "text/HTML "))

{

InputStream iPStm = messagePart.getInputStream();

BufferedReader bufreader = new BufferedReader(new InputStreamReader(iPStm));

String thisLine = bufreader.readLine();

while (thisLine != null)

{

System.out.PRintln( "thisLine: "+thisLine);

thisLine = bufreader.readLine();

}

}

*/

System.out.PRintln( "------------------------------------------------------------ ");

message[i].setFlag(Flags.Flag.DELETED,true);

}

folder.close(true);

store.close();

}

catch(Exception ej2)

{

System.out.PRintln(ej2);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值