ABAP技术:发送内容带有图片的电子邮件
Send an email with image in thebody along with the text.发送内容带有图片的电子邮件
We come across a requirment to have an image inthe body of an email. For example, we may need to have an image to be embedded besidesignature, for examplecompany logo.
我们可能遇到要将图片放在邮件正文中的需求,例如:我们可能需要一个带图的签名,例如放着公司LOGO。
Lets see how to achieve it stepby step. 让我们来看看如何一步一步实现
Before embedding an image,Let's have a brief look how to send an email usingCL_BCS with an example code snippet keeping the main emphasis on the image part. These steps will be useful while embedding the image.
潜入图片之前,让我用示例代码片段简单介绍下如何使用CL_BCS发送一封带图片的电子邮件。嵌入图片时,这些步骤都会用到。
First step is to create persistent. 第一步创建persistent
o Use the method CREATE_PERSISTENT of the class CL_BCS tosend request object of the standard class CL_BCS.
o Create BCS document
ob_bcs = cl_bcs=>create_persistent( ).
Second step is to create document.第二步创建document·
Use the method CREATE_DOCUMENT of the classCL_BCS to create the message body.
ob_document =cl_document_bcs=>create_document(i_type = 'HTM'
i_subject = fp_subject
i_text =fp_it_text ).
Fill the fp_it_text with the html codingwhich you want to get displayed in the message body like below.
填写fp_it_text你想要得到像下面显示在邮件正文中的HTML代码。
[plain]
DATA : wa_text TYPE soli.
wa_text = '<p><font size="3" face="arial">Thank you </font></p><br/>'.
APPEND wa_text TO fp_it_text.
Fill the subject line with the appropriatesubject line to be displayed on the mail.
填写合适的的主题行,会显示在邮件的主题行上。
[plain]
Data : lv_obj_des TYPE so_obj_des.
lv_obj_des = ‘test mail’.
We can also fill other parameters like i_type which indicates the type of thedocument which we are going to create.
我们也可以加入其它参数像i_type(表示我们要创建的文件类型)
I_length specifies the length of the document inbytes and it is an optional parameter.
I_length指定的长度,以字节为单位的文件,它是一个可选的参数。
I_language indicates the language and it is anoptional parameter.
I_language表示语言,它是一个可选的参数。
I_importance indicates the priority of the mail andit is also an optional parameter. (1- high 5-medium, 9 – low and the default is5 which is medium).
i_importance表示的电子邮件的优先级,并且它也是一个可选参数。(1 - 高,5中,9 - 低,默认值是5既是中)。
I_sensitivity indicates the confidentiality of the mail and it isalso an optional parameter. (P – Confidential, F – functional, O –standard).
I_sensitivity表示保密的邮件,这是一个可选的参数。(P - 机密,F – 实用,O – 正常)。
I_hex specifies the content has to bedisplayed in binary format and it is also optional.
i_hex指定的内容用二进制格式,它也是可选的。
I_sender specifies the reference address.
i_sender指定的参考地址。
Third step is to add an attachment to themail. 第三步是将附件添加到邮件中。
Use the method ADD_ATTACHMENT of the classCL_BCS to attach a document to the mail.
使用类CL_BCS的方法ADD_ATTACHMENT将文件附加给邮件
[plain]
ob_document->add_attachment(
i_attachment_type = 'HTM'
i_attachment_subject = 'XXXX’
i_att_content_hex = it_data ).
Since attachment type is HTML pass HTM to i_attachment_type.
由于附件类型是HTML,传递HTM到i_attachment_type。
Pass the name which you want it to be on attachment(attachmentname)to i_attachment_subject.
你希望它在附件的名称传递给i_attachment_subject.
In i_att_content_hex pass the data using the table IT_DATAwhich is of table length 255 and it will have contents.
在这个 i_att_content_hex 传递内表IT_DATA。
I_attachment_size is the size of the attachment and it isan optional parameter.
I_attachment_size的附件大小,它是一个可选的参数。
I_language specifies the language of theattachment and it is also an optional parameter.
I_language指定语言的附件,它也是一个可选的参数。
I_attachment_text is used ifthe created document is in text format and it is also an optional parameter.
I_attachment_text,如果创建的文件是文本格式,它也是一个可选的参数。
Fourthstep is to set document. 第四步是设置文档。
Use the method SET_DOCUMENT of the classCL_BCS to set the document.
用类CL_BCS中的方法SET_DOCUMENT设置文档
It is used to pass an object to the sendrequest created using CREATE_PERSISTENT method of class CL_BCS.
它是用来传递一个对象发送请求
§ ob_bcs->set_document( EXPORTING i_document =ob_document ) .
Fifth step is to add recipient.. 第五步填写收件人
Use the method ADD_RECIPENT of the classCL_BCS to add recipient address to the mail.
使用类CL_BCS中的方法ADD_RECIPENT 填加收件人电子邮件地址
lv_mailid = lv_emailaddr.
ob_recipient_internet =cl_cam_address_bcs=>create_internet_address( i_address_string = lv_mailid ).
ob_bcs->add_recipient( EXPORTING i_recipient =ob_recipient_internet ).
Parameter i_recipient has to be populated using the referencevariable which further refers to the inte易做图ce IF_RECIPIENT_BCS. Now use theinstance method
来填充参数i_recipient有进一步的参考变量是指接口IF_RECIPIENT_BCS。
现在使用实例方法
CREATE_INTERNET_ADDRESS of the classCL_CAM_ADDRESS_BCS and pass the email id to the i_address_string parameter.
Now pass the return parameterob_recipient_string to i_recipient parameter of method
ADD_RECIPIENT.
现在通过的的返回参数ob_recipient_string到i_recipient参数的方法ADD_RECIPIENT
I_copy parameter is used when we want to send a copy ofthe message and it is an optional parameter.
I_copy参数,我们要发送邮件的副本,它是一个可选的参数。
I_no_forward is set when we don’t want to allowforwarding and it is an optional parameter.
I_no_forward是否允许转发,它是一个可选的参数。
I_blind_copy is set when want to send using BCCoption and it is also an optional parameter.
I_blind_copy,设置要发送的使用BCC选项,它也是一个可选的参数。
I_express is set when we want to send an expressmail and it is also an optional parameter.
I_express发送的快件时设置的,它也是一个可选的参数。
If we want to send mail to multiple Email IDswe have to call the above steps in a loop. Keep all the email ids in a tablea
补充:综合编程 , 其他综合 ,
上一个:使用 TypeProviders
下一个:再来看看快排算法之一次排序过程