
    dhg                         S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
JrJr  SSKJr  SSKJrJr  SSKJr   " S	 S
\5      r " S S\5      rg)zSend Gmail messages.    N)MIMEMultipart)MIMEText)AnyDictListOptionalTypeUnion)CallbackManagerForToolRun)	BaseModelField)GmailBaseToolc                       \ rS rSr% Sr\" SSS9r\\S'   \" SSS9r	\
\\\   4   \S'   \" SS	S9r\\S
'   \" SSS9r\\
\\\   4      \S'   \" SSS9r\\
\\\   4      \S'   Srg)SendMessageSchema   zInput for SendMessageTool..zThe message to send.)descriptionmessagezThe list of recipients.tozThe subject of the message.subjectNzThe list of CC recipients.cczThe list of BCC recipients.bcc )__name__
__module____qualname____firstlineno____doc__r   r   str__annotations__r   r
   r   r   r   r   r   __static_attributes__r       d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/gmail/send_message.pyr   r      s    $*GS  !&-!Bc49n  1GS  +00+BsDI~&'  ,11,C%T#Y'	( r!   r   c                   ,   \ rS rSr% SrSr\\S'   Sr\\S'   \	r
\\	   \S'     SS	\S
\\\\   4   S\S\\\\\   4      S\\\\\   4      S\\\4   4S jjr   SS	\S
\\\\   4   S\S\\\\\   4      S\\\\\   4      S\\   S\4S jjrSrg)GmailSendMessage'   z#Tool that sends a message to Gmail.send_gmail_messagenamezJUse this tool to send email messages. The input is the message, recipientsr   args_schemaNr   r   r   r   r   returnc                    [        5       nUR                  [        US5      5        SR                  [	        U[
        5      (       a  UOU/5      US'   X6S'   Ub,  SR                  [	        U[
        5      (       a  UOU/5      US'   Ub,  SR                  [	        U[
        5      (       a  UOU/5      US'   [        R                  " UR                  5       5      R                  5       nSU0$ )zCreate a message for an email.htmlz, ToSubjectCcBccraw)
r   attachr   join
isinstancelistbase64urlsafe_b64encodeas_bytesdecode)selfr   r   r   r   r   mime_messageencoded_messages           r"   _prepare_message!GmailSendMessage._prepare_message0   s     %HWf56!YYZD-A-ArtLT")Y>!%B1E1E2B4!PL?"&)):c43H3HCse"TL 22<3H3H3JKRRT''r!   run_managerc                     U R                  XX4US9nU R                  R                  5       R                  5       R	                  SUS9nUR                  5       n	SU	S    3$ ! [         a  n
[        SU
 35      eSn
A
ff = f)zRun the tool.)r   r   me)userIdbodyzMessage sent. Message Id: idzAn error occurred: N)r<   api_resourceusersmessagessendexecute	Exception)r9   r   r   r   r   r   r>   create_messagesend_messagesent_messageerrors              r"   _runGmailSendMessage._runG   s    
	;!227TW2XN!!'')T7 
 (//1L/T0B/CDD 	;1%9::	;s   AA! !
A>+A99A>r   )NN)NNN)r   r   r   r   r   r'   r   r   r   r   r(   r	   r
   r   r   r   r   r<   r   rN   r    r   r!   r"   r$   r$   '   s@   -$D#$T   ,=K'(< /3/3(( #tCy.!( 	(
 U3S	>*+( eCcN+,( 
c3h(8 /3/3;?;; #tCy.!; 	;
 U3S	>*+; eCcN+,; 78; 
; ;r!   r$   )r   r5   email.mime.multipartr   email.mime.textr   typingr   r   r   r   r	   r
   langchain_core.callbacksr   pydanticr   r   $langchain_community.tools.gmail.baser   r   r$   r   r!   r"   <module>rV      s8      . $ 9 9 > % >	 24;} 4;r!   