+
    bi&                     $   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt	^ RI
Ht ^ RIHt ^ RIHt ^ RI	Ht ^ RIHt ^ RIHtHt ^ RIHt ]P0                  ! 4       R	,          tR
 tR tR tRR ltRR ltR tR t ]!R8X  d
   ] ! 4        R# R# )a[  
Send email via SMTP or Resend API.

Usage:
    python3 send_email.py --to <recipient> --subject <subject> --body <body> [--html] [--attachments file1,file2]
    python3 send_email.py --to <recipient> --subject <subject> --body <body> --provider resend

Providers:
    smtp (default) - Traditional SMTP
    resend         - Resend.com API (simpler setup)

Environment variables (or ~/.smtp_config):
    # SMTP
    SMTP_HOST       - SMTP server hostname
    SMTP_PORT       - SMTP server port (default: 587)
    SMTP_USER       - SMTP username
    SMTP_PASSWORD   - SMTP password or app password
    SMTP_FROM       - From email address
    SMTP_USE_SSL    - Use SSL (true for port 465)
    
    # Resend
    RESEND_API_KEY  - Resend API key (or in ~/.smtp_config as "resend_api_key")
    RESEND_FROM     - From address (or in ~/.smtp_config as "resend_from")
N)MIMEText)MIMEMultipart)MIMEBase)encoders)Path)Requesturlopen)	HTTPErrorz.smtp_configc            	        / p \         P                  4       '       d8    \        \         4      ;_uu_ 4       p\        P                  ! V4      p RRR4       \        P                  ! RV P                  R4      4      V R&   \        \        P                  ! RV P                  RR	4      4      4      V R&   \        P                  ! R
V P                  R4      4      V R&   \        P                  ! RV P                  R4      4      V R&   \        P                  ! RV P                  RV P                  R4      4      4      V R&   \        P                  ! RV P                  RR4      4      p\        V\        4      '       d   W0R&   M\        V4      P!                  4       R8H  V R&   \        P                  ! RV P                  R4      4      V R&   \        P                  ! RV P                  RR4      4      V R&   V #   + '       g   i     EL; i  \
         d1   p\        R\          RT 2\        P                  R7        Rp?ELRp?ii ; i)z4Load config from environment or ~/.smtp_config file.NzWarning: Failed to load z: file	SMTP_HOSThost	SMTP_PORTportiK  	SMTP_USERuserSMTP_PASSWORDpassword	SMTP_FROMfromSMTP_USE_SSLuse_sslFtrueRESEND_API_KEYresend_api_keyRESEND_FROMresend_fromzonboarding@resend.dev)CONFIG_FILEexistsopenjsonload	Exceptionprintsysstderrosgetenvgetint
isinstanceboolstrlower)configfeuse_ssl_values       J/Users/tonyclaw/.openclaw/workspace/skills/smtp-send/scripts/send_email.pyload_configr4   -   s   F 	Rk""a1 # YY{FJJv,>?F6N;

630GHIF6NYY{FJJv,>?F6N?FJJz4JKF:YY{FJJvvzz&?Q,RSF6N IInfjjE.JKM-&&)y.446&@y  "yy)96::FV;WXFIImVZZOf5ghF=M1 #"" 	R,[MA3?cjjQQ	Rs4   H G1H 1H	<H H I %H;;I c                   a  . ROp\         ;QJ d    V 3R lV 4       F  '       d   K   R# 	  R# ! V 3R lV 4       4      # )zCheck if SMTP config is valid.c              3   F   <"   T F  pSP                  V4      x  K  	  R # 5i)N)r)   ).0r0   r/   s   & r3   	<genexpr>'validate_smtp_config.<locals>.<genexpr>Q   s     /hvzz!}}hs   !FT)r   r   r   )all)r/   requireds   f r3   validate_smtp_configr<   N   s1    +H3/h/33/3/3/h///    c                6    \        V P                  R4      4      # )z Check if Resend config is valid.r   )r,   r)   )r/   s   &r3   validate_resend_configr?   S   s    

+,--r=   c                h   V'       EdA   \        4       pV R,          VR&   WR&   W&R&   \        P                  P                  RR7      VR&   \	        Y4'       d   RMR	4      pVP                  V4       V F  p\        V4      pVP                  4       '       g!   \        R
V 2\        P                  R7       KD  \        VR4      ;_uu_ 4       p	\        RR4      p
V
P                  V	P                  4       4       RRR4       \        P                   ! X
4       V
P#                  RRVP$                   24       VP                  V
4       K  	  ML\	        Y4'       d   RMR	4      pV R,          VR&   WR&   W&R&   \        P                  P                  RR7      VR&    V R,          '       d>   \&        P(                  ! 4       p\*        P,                  ! V R,          V R,          VR7      pM5\*        P.                  ! V R,          V R,          4      pVP1                  4        VP3                  V R,          V R,          4       VP5                  V4       VP7                  4        \        RV 24       R#   + '       g   i     EL{; i  \8         d*   p\        RT 2\        P                  R7        Rp?R# Rp?ii ; i)zSend email via SMTP.r   FromToSubjectz	proton.me)domainz
Message-IDhtmlplainWarning: Attachment not found: r   rbapplicationzoctet-streamNzContent-Dispositionzattachment; filename=r   r   r   )contextr   r   u   ✓ Email sent via SMTP to TzSMTP error: F)r   emailutils
make_msgidr   attachr   r   r$   r%   r&   r    r   set_payloadreadr   encode_base64
add_headernamesslcreate_default_contextsmtplibSMTP_SSLSMTPstarttlsloginsend_messagequitr#   )r/   tosubjectbodyis_htmlattachmentsmessagemsg_bodyfilepathr0   partrJ   serverr1   s   &&&&&&        r3   send_via_smtprg   W   s$    {/ .$	 % 6 6k 6 JDG&Ax #HH~H??$$7zBTh%%~>  * & ""4(OO15J8==/3Z[NN4  $ 47@ .$	 % 6 6k 6 J)002G%%fVnfVngVF\\&.&.AFOOVF^VJ%78G$+B4019 &%%:  QC szz2s+   ,I)I= &CI= )I:=J1J,,J1c                   V R,          pV R,          pRVRV.RV/pV'       d   W8R&   MW8R&   V'       d   . p	V F  p
\        V
4      p
V
P                  4       '       g!   \        RV
 2\        P                  R	7       KD  \        V
R
4      ;_uu_ 4       p\        P                  ! VP                  4       4      P                  R4      pRRR4       V	P                  RV
P                  RX/4       K  	  V	'       d   WR&    \        R\        P                  ! V4      P                  R4      RRV 2RRRR/RR7      p\!        V^R7      ;_uu_ 4       p\        P"                  ! VP                  4       P                  R4      4      p\        RV RVP%                  RR4       R24        RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i  \&         dV   pTP                  4       P                  R4      p\        R TP(                   R!T 2\        P                  R	7        Rp?R"# Rp?i\*         d*   p\        R#T 2\        P                  R	7        Rp?R"# Rp?ii ; i)$zSend email via Resend API.r   r   r   r]   r^   rE   textrG   r   rH   zutf-8Nfilenamecontentra   zhttps://api.resend.com/emailsAuthorizationzBearer zContent-Typezapplication/jsonz
User-Agentz&Mozilla/5.0 (compatible; Clawdbot/1.0)POST)dataheadersmethod)timeoutu   ✓ Email sent via Resend to z (id: idunknown)TzResend API error: z - FzResend error: )r   r   r$   r%   r&   r    base64	b64encoderP   decodeappendrS   r   r!   dumpsencoder   loadsr)   r	   coder#   )r/   r]   r^   r_   r`   ra   api_key	from_addrpayloadattachment_listrd   r0   rk   reqresponseresultr1   
error_bodys   &&&&&&            r3   send_via_resendr      s   %&G}%I 		rd7G  #HH~H??$$7zBTh%% **16684;;GD & ""HMM7$  $ %4M"+G$++G477)!4 2F
 	
 S"%%ZZ 6 6w ?@F1"VFJJtY<W;XXYZ[ &%1 &%0 &%%
  VVX__W-
"166(#j\:L qc"4sW   4F.=AG AG$G .F>G	G G I' A
H00I'=I'>I""I'c                     \        R\        P                  R7       \        R\         R2\        P                  R7       \        R\        P                  R7       R# )zPrint configuration help.z$Error: No email provider configured.r   z
Create z with SMTP or Resend settings:a|  
Option 1 - SMTP (163/QQ/Gmail/etc):
{
    "host": "smtp.163.com",
    "port": 465,
    "user": "your-email@163.com",
    "password": "your-auth-code",
    "from": "your-email@163.com",
    "use_ssl": true
}

Option 2 - Resend (recommended, simpler):
{
    "resend_api_key": "re_xxxxx",
    "resend_from": "you@your-domain.com"
}

Get a free Resend API key at: https://resend.com
N)r$   r%   r&   r    r=   r3   print_config_helpr      s?    	
0szzB	Ik]"@
A

S	 $ **%r=   c                     \         P                  ! R R7      p V P                  RRRR7       V P                  RRRR7       V P                  RRR	R7       V P                  R
RRR7       V P                  RRR7       V P                  R. RORRR7       V P                  4       p\	        4       pRpVP
                  '       d8   VP
                  P                  R4       Uu. uF  qDP                  4       NK  	  ppVP                  p\        V4      p\        V4      pVR8X  d7   V'       d   RpM+V'       d   RpM \        4        \        P                  ! ^4       VR8X  d:   V'       g2   \        R\        P                  R7       \        P                  ! ^4       VR8X  d:   V'       g2   \        R\        P                  R7       \        P                  ! ^4       VR8X  d9   \!        W!P"                  VP$                  VP&                  VP(                  V4      pM7\+        W!P"                  VP$                  VP&                  VP(                  V4      pV'       g   VP                  R8X  d   VR8X  d\   V'       dT   \        R\        P                  R7       \+        W!P"                  VP$                  VP&                  VP(                  V4      pMaVR8X  d[   V'       dS   \        R\        P                  R7       \!        W!P"                  VP$                  VP&                  VP(                  V4      p\        P                  ! V'       d	   ^ 4       R# ^4       R# u upi )zSend email via SMTP or Resend)descriptionz--toTzRecipient email address)r;   helpz	--subjectzEmail subjectz--bodyz
Email bodyz--html
store_truezSend as HTML email)actionr   z--attachmentsz-Comma-separated list of attachment file paths)r   z
--providersmtpresendautozEmail provider (default: auto))choicesdefaultr   N,z3Error: SMTP not configured. Set host/user/password.r   z1Error: Resend not configured. Set resend_api_key.zTrying SMTP fallback...zTrying Resend fallback...)r   r   r   )argparseArgumentParseradd_argument
parse_argsr4   ra   splitstripproviderr<   r?   r   r%   exitr$   r&   r   r]   r^   r_   rE   rg   )	parserargsr/   ra   pr   has_smtp
has_resendsuccesss	            r3   mainr      sy   $$1PQF
4MN
dI
4lC
<PQ
.]^
.HRX=  ? D ]F K*.*:*:*@*@*EF*EQwwy*EF }}H#F+H'/J6HHHHQK 6(C#**U8JA

S 8!&''4<<DIIWbctyy$))U`a t}}.xH+#**=#FGGT\\499diiYdeGJ-CJJ?%fggt||TYYPTPYPY[fgGHH'Q!q!S Gs   M__main__)FN)"__doc__r   rV   rT   r%   r'   r!   ru   email.utilsrK   email.mime.textr   email.mime.multipartr   email.mime.baser   r   pathlibr   urllib.requestr   r   urllib.errorr	   homer   r4   r<   r?   rg   r   r   r   __name__r   r=   r3   <module>r      s   2   
 
 	    $ . $   + "iikN*B0
.2h=~0;"z zF r=   