Rename email fields
Introduction
When rendering email messages, by default the API uses the English language to render field labels such as From, To, Subject etc. There might be the case when you want to change the label of the fields in email message’s header. GroupDocs.Viewer Cloud is flexible enough to allow you to use the custom field labels for email header. The API provides a new property FieldLabels in EmailOptions class to change the field labels. Following code sample shows how to use custom field labels.
API Usage
There are steps that usage of GroupDocs.Viewer Cloud consists of:
- Upload input document into cloud storage
- Render document or get document info
- Download rendered document from storage
Steps 1 and 3 are storage operations, please refer to this File API documentation for usage details.
Swagger UI lets you call this REST API directly from the browser.
cURL REST Example
* First get JSON Web Token
* Please get your Client Id and Client Secret from https://dashboard.groupdocs.cloud/applications. Kindly place Client Id in "client_id" and Client Secret in "client_secret" argument.
curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=xxxx&client_secret=xxxx" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
* cURL example to get document information
curl -v "https://api.groupdocs.cloud/v2.0/viewer/view" \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer <jwt token>"
-d "{
'FileInfo': {
'FilePath': 'SampleFiles/sample.msg'
},
'ViewFormat': 'HTML',
'RenderOptions': {
'EmailOptions': {
'FieldLabels': [
{
'Field': 'From',
'Label': 'Sender'
},
{
'Field': 'To',
'Label': 'Receiver'
}
]
}
}
}"
{
"pages": [
{
"number": 1,
"resources": null,
"path": "viewer/sample_msg/sample_page_1.html",
"downloadUrl": "https://api.groupdocs.cloud/v2.0/viewer/storage/file/viewer/sample_msg/sample_page_1.html"
}
],
"attachments": [],
"file": null
}
SDKs
The API is completely independent of your operating system, database system or development language. We provide and support API SDKs in many development languages in order to make it even easier to integrate. You can see our available SDKs list here.
SDK Examples
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-dotnet-samples
string MyClientSecret = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
string MyClientId = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
var configuration = new Configuration(MyClientId, MyClientSecret);
var apiInstance = new ViewApi(configuration);
var viewOptions = new ViewOptions
{
FileInfo = new FileInfo
{
FilePath = "SampleFiles/sample.msg"
},
ViewFormat = ViewOptions.ViewFormatEnum.HTML,
RenderOptions = new HtmlOptions
{
EmailOptions = new EmailOptions
{
FieldLabels = new List<FieldLabel>
{
new FieldLabel {Field = "From", Label = "Sender"},
new FieldLabel {Field = "To", Label = "Receiver"}
}
}
}
};
var response = apiInstance.CreateView(new CreateViewRequest(viewOptions));
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-java-samples
string MyClientSecret = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
string MyClientId = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyClientId, MyClientSecret);
ViewApi apiInstance = new ViewApi(configuration);
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("SampleFiles/sample.msg");
ViewOptions viewOptions = new ViewOptions();
viewOptions.setFileInfo(fileInfo);
viewOptions.setViewFormat(ViewFormatEnum.HTML);
HtmlOptions renderOptions = new HtmlOptions();
EmailOptions emailOptions = new EmailOptions();
emailOptions.addFieldLabelsItem(GetFieldLabel("From", "Sender"));
emailOptions.addFieldLabelsItem(GetFieldLabel("To", "Receiver"));
renderOptions.setEmailOptions(emailOptions);
viewOptions.setRenderOptions(renderOptions);
ViewResult response = apiInstance.createView(new CreateViewRequest(viewOptions));
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-java-samples
string MyClientSecret = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
string MyClientId = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyClientId, MyClientSecret);
ViewApi apiInstance = new ViewApi(configuration);
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("SampleFiles/sample.msg");
ViewOptions viewOptions = new ViewOptions();
viewOptions.setFileInfo(fileInfo);
viewOptions.setViewFormat(ViewFormatEnum.HTML);
HtmlOptions renderOptions = new HtmlOptions();
EmailOptions emailOptions = new EmailOptions();
emailOptions.addFieldLabelsItem(GetFieldLabel("From", "Sender"));
emailOptions.addFieldLabelsItem(GetFieldLabel("To", "Receiver"));
renderOptions.setEmailOptions(emailOptions);
viewOptions.setRenderOptions(renderOptions);
ViewResult response = apiInstance.createView(new CreateViewRequest(viewOptions));
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-php-samples
use GroupDocs\Viewer\Model;
use GroupDocs\Viewer\Model\Requests;
$ClientId = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
$ClientSecret = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid($ClientId);
$configuration->setAppKey($ClientSecret);
$apiInstance = new GroupDocs\Viewer\ViewApi($configuration);
$viewOptions = new Model\ViewOptions();
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("SampleFiles/sample.msg");
$viewOptions->setFileInfo($fileInfo);
$viewOptions->setViewFormat(Model\ViewOptions::VIEW_FORMAT_HTML);
$renderOptions = new Model\HtmlOptions();
$emailOptions = new Model\EmailOptions();
$emailOptions->setFieldLabels([
self::GetFieldLabel("From", "Sender"),
self::GetFieldLabel("To", "Receiver")
]);
$renderOptions->setEmailOptions($emailOptions);
$viewOptions->setRenderOptions($renderOptions);
$request = new Requests\CreateViewRequest($viewOptions);
$response = $apiInstance->createView($request);
// For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-node-samples
global.viewer# require("groupdocs-viewer-cloud");
global.clientId = "XXXX-XXXX-XXXX-XXXX"; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
global.clientSecret = "XXXXXXXXXXXXXXXX"; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
global.viewApi = viewer_cloud.ViewApi.fromKeys(clientId, clientSecret);
let fileInfo = new viewer_cloud.FileInfo();
fileInfo.filePath = "SampleFiles/sample.msg";
let viewOptions = new viewer_cloud.ViewOptions();
viewOptions.fileInfo = fileInfo;
viewOptions.viewFormat = viewer_cloud.ViewOptions.ViewFormatEnum.HTML;
viewOptions.renderOptions = new viewer_cloud.HtmlOptions();
viewOptions.renderOptions.emailOptions = new viewer_cloud.EmailOptions();
let fieldLabel1 = new viewer_cloud.FieldLabel();
fieldLabel1.field = "From";
fieldLabel1.label = "Sender";
let fieldLabel2 = new viewer_cloud.FieldLabel();
fieldLabel2.field = "To";
fieldLabel2.label = "Receiver";
viewOptions.renderOptions.emailOptions.fieldLabels = [fieldLabel1, fieldLabel2];
let request = new viewer_cloud.CreateViewRequest(viewOptions);
let response = await viewApi.createView(request);
# For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-python-samples
import groupdocs_viewer_cloud
client_id = "XXXX-XXXX-XXXX-XXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
client_secret = "XXXXXXXXXXXXXXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
apiInstance = groupdocs_viewer_cloud.ViewApi.from_keys(client_id, client_secret)
view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "SampleFiles/sample.msg"
view_options.view_format = "HTML"
view_options.render_options = groupdocs_viewer_cloud.HtmlOptions()
view_options.render_options.email_options = groupdocs_viewer_cloud.EmailOptions()
field_label1 = groupdocs_viewer_cloud.FieldLabel()
field_label1.field = "From"
field_label1.label = "Sender"
field_label2 = groupdocs_viewer_cloud.FieldLabel()
field_label2.field = "To"
field_label2.label = "Receiver"
view_options.render_options.email_options.field_labels = [field_label1, field_label2]
request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
response = apiInstance.create_view(request)
# For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-ruby-samples
require 'groupdocs_viewer_cloud'
$client_id = "XXXX-XXXX-XXXX-XXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
$client_secret = "XXXXXXXXXXXXXXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
apiInstance = GroupDocsViewerCloud::ViewApi.from_keys($client_id, $client_secret)
viewOptions = GroupDocsViewerCloud::ViewOptions.new
viewOptions.file_info = GroupDocsViewerCloud::FileInfo.new
viewOptions.file_info.file_path = "SampleFiles/sample.msg"
viewOptions.view_format = "HTML"
viewOptions.render_options = GroupDocsViewerCloud::HtmlOptions.new
viewOptions.render_options.email_options = GroupDocsViewerCloud::EmailOptions.new
field_label1 = GroupDocsViewerCloud::FieldLabel.new
field_label1.field = "From"
field_label1.label = "Sender"
field_label2 = GroupDocsViewerCloud::FieldLabel.new
field_label2.field = "To"
field_label2.label = "Receiver"
viewOptions.render_options.email_options.field_labels = [field_label1, field_label2]
request = GroupDocsViewerCloud::CreateViewRequest.new(viewOptions)
response = apiInstance.create_view(request)