@@ -156,48 +156,60 @@ Pass the components of the messages such as To, From, Subject, HTML and text par
156156``` python
157157import os
158158from pathlib import Path
159-
160159from mailgun.client import Client
161160
161+ key: str = os.environ[" APIKEY" ]
162+ domain: str = os.environ[" DOMAIN" ]
163+ client: Client = Client(auth = (" api" , key))
164+
165+
166+ def post_message () -> None :
167+ # Messages
168+ # POST /<domain>/messages
169+ data = {
170+ " from" : os.getenv(
" MESSAGES_FROM" ,
" [email protected] " ),
171+ " to" : os.getenv(
" MESSAGES_TO" ,
" [email protected] " ),
172+ " subject" : " Hello from python!" ,
173+ " text" : " Hello world!" ,
174+ " o:tag" : " Python test" ,
175+ }
176+
177+ req = client.messages.create(data = data, domain = domain)
178+ print (req.json())
179+ ```
180+
181+ #### Send an email with attachments
182+
183+ ``` python
184+ import os
185+ from pathlib import Path
186+ from mailgun.client import Client
162187
163188key: str = os.environ[" APIKEY" ]
164189domain: str = os.environ[" DOMAIN" ]
165- html: str = """ <body style="margin: 0; padding: 0;">
166- <table border="1" cellpadding="0" cellspacing="0" width="100%">
167- <tr>
168- <td>
169- Hello!
170- </td>
171- </tr>
172- </table>
173- </body>"""
174190client: Client = Client(auth = (" api" , key))
175191
176192
177193def post_message () -> None :
178194 # Messages
179195 # POST /<domain>/messages
180196 data = {
181- " from" : os.environ[" MESSAGES_FROM" ],
182- " to" : os.environ[" MESSAGES_TO" ],
183- " cc" : os.environ[" MESSAGES_CC" ],
184- " subject" : " Hello Vasyl Bodaj" ,
185- " html" : html,
197+ " from" : os.getenv(
" MESSAGES_FROM" ,
" [email protected] " ),
198+ " to" : os.getenv(
" MESSAGES_TO" ,
" [email protected] " ),
199+ " subject" : " Hello from python!" ,
200+ " text" : " Hello world!" ,
186201 " o:tag" : " Python test" ,
187202 }
203+
188204 # It is strongly recommended that you open files in binary mode.
189205 # Because the Content-Length header may be provided for you,
190206 # and if it does this value will be set to the number of bytes in the file.
191207 # Errors may occur if you open the file in text mode.
192208 files = [
193209 (
194210 " attachment" ,
195- (" test1.txt" , Path(" mailgun/doc_tests/files/test1.txt" ).read_bytes()),
196- ),
197- (
198- " attachment" ,
199- (" test2.txt" , Path(" mailgun/doc_tests/files/test2.txt" ).read_bytes()),
200- ),
211+ (" test1.txt" , Path(" test1.txt" ).read_bytes()),
212+ )
201213 ]
202214
203215 req = client.messages.create(data = data, files = files, domain = domain)
@@ -210,13 +222,10 @@ def post_message() -> None:
210222
211223``` python
212224import os
213-
214225from mailgun.client import Client
215226
216-
217227key: str = os.environ[" APIKEY" ]
218228domain: str = os.environ[" DOMAIN" ]
219-
220229client: Client = Client(auth = (" api" , key))
221230
222231
@@ -229,7 +238,7 @@ def get_domains() -> None:
229238 print (data.json())
230239```
231240
232- #### Create a domain
241+ #### Get domains details
233242
234243``` python
235244def get_simple_domain () -> None :
0 commit comments