我有个问题; 当其他用户邀请他时,我想编写一个 java 代码,用于向我网站上的注册用户发送自动电子邮件。然后被邀请者将接受或拒绝电子邮件中的邀请。请指导我…………
问问题
2610 次
1 回答
1
让他单击该电子邮件中的链接。
电子邮件代码:
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
public void sendEmail(String aFromEmailAddr, String aToEmailAddr,
String aSubject, String aBody){
//Here, no Authenticator argument is used (it is null).
//Authenticators are used to prompt the user for user
//name and password.
Session session = Session.getDefaultInstance( fMailServerConfig, null );
MimeMessage message = new MimeMessage( session );
try {
//the "from" address may be set in code, or set in the
//config file under "mail.from" ; here, the latter style is used
//message.setFrom( new InternetAddress(aFromEmailAddr) );
message.addRecipient(
Message.RecipientType.TO, new InternetAddress(aToEmailAddr)
);
message.setSubject( aSubject );
message.setText( aBody );
Transport.send( message );
}
catch (MessagingException ex){
System.err.println("Cannot send email. " + ex);
}
}
您可以在该电子邮件中放置一个链接。我相信邮件客户端支持基本的 HTML,因此您可以执行以下操作:
Hi PersonWithANameEnteredByTheGuyWhoInvitedYou,
NameOfTheGuyWhoInvitedYou invited you, click here to accept his invitation:
<a href="http://mydomain.com/accept?param=ridiculousLongTokenToVerifyTheRequestAndIdentifyThePersonThatClickedIt">ACCEPT!</a>
于 2012-07-01T16:57:41.887 回答