我希望发送一封电子邮件,以填充电子邮件地址,电子邮件的主题和正文。我尝试了以下操作,但无法正常工作。有人可以协助吗?
<script src="/SiteAssets/jquery-3.4.0.js"></script>
<script type="text/javascript">
function SendMail()
{
var emailID = getEmailFromPeoplePicker('User Requesting Assistance');
var subject = getSubject('Ticket Number');
var body = getBody('Description of Problem');
location.href = "mailto:"+emailID+"?subject="+subject+"&body="+body;
}
function getSubject(subject)
{
return $('input[title="'+subject+'"]').val();
}
function getBody(body)
{
return $('input[title="'+body+'"]').val();
}
function getEmailFromPeoplePicker(title) {
//Get the people picker field
var ppDiv = $("div[title='" + title + "']")[0];
//cast the object as type PeoplePicker
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv.id];
//Get list of users from field (assuming 1 in this case)
var userList = peoplePicker.GetAllUserInfo();
var userInfo = userList[0];
var userEmail;
//The description field contains the login info without the lookup extras. In new forms this
//field can be undefined depending on the field being checked. Only check if userInfo is
//initialized.
if(userInfo != null)
{
userEmail = userInfo.EntityData.Email;
}
return userEmail;
}
</script>
<a href="#" onclick="SendMail()">Email User</a>
答案 0 :(得分:0)
如果您在帖子中使用代码,则“票号”和“问题描述”将全部为单个文本字段。如果“问题描述”字段是多行文本字段,则该代码将无效。
要获取多行文本,我们可以使用下面的代码来实现。如果无法获取用户的电子邮件,则需要检查用户是否有电子邮件(转到用户个人资料以进行检查)。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
function SendMail(){
var emailID = getEmailFromPeoplePicker('User Requesting Assistance');
var subject = getSubject('Ticket Number');
var body = getBody('Description of Problem');
location.href = "mailto:"+emailID+"?subject="+subject+"&body="+body;
}
function getSubject(subject){
return $('input[title="'+subject+'"]').val();
}
function getBody(body){
return $('nobr:contains("'+body+'")').closest('tr').find('.ms-rtestate-write')[0].innerText;
}
function getEmailFromPeoplePicker(title) {
//Get the people picker field
var ppDiv = $("div[title='" + title + "']")[0];
//cast the object as type PeoplePicker
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv.id];
//Get list of users from field (assuming 1 in this case)
var userList = peoplePicker.GetAllUserInfo();
var userInfo = userList[0];
var userEmail;
//The description field contains the login info without the lookup extras. In new forms this
//field can be undefined depending on the field being checked. Only check if userInfo is
//initialized.
if(userInfo != null){
userEmail = userInfo.EntityData.Email;
}
return userEmail;
}
</script>
<a href="#" onclick="SendMail()">Email User</a>