2012-07-01 29 views
-2

我有一個問題,當一些其他用戶邀請他在我的網站發送自動生成的電子郵件給用戶; 我想寫一個java代碼,當一些其他用戶邀請他在我的網站發送的電子郵件自動向註冊用戶。然後,受邀者接受或拒絕該電子郵件中邀請。 請指引我...........如何「通過isuing java代碼」

回答

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> 
+0

thanks;朋友.... – Zeeshan8989