Foghlaim conas ríomhphoist a sheoladh go héasca le Python ag baint úsáide as an API Aspose
. Le leabharlann Aspose.Email do Python trí .NET is féidir leat teachtaireachtaí ríomhphoist a chruthú, a thiontú, a sheoladh, a fháil nó a láimhseáil, lena n-áirítear MSG
, PST
, EML
, EMLX
, agus formáidí comhaid eile.

Aspose.Email for Python via .NET
is a robust and powerful email programming API for creating, manipulating, and converting common email message formats without concern about the complexities of the underlying format execution. It’s an easy-to-use class library assembled to produce an outstanding and robust email programming component. Aspose.Email for Python saves time and effort by allowing you to quickly and easily code complex message file handling into your applications fast and easily.
Is féidir lenár API a úsáid chun raon leathan tascanna a chur i bhfeidhm i bhfeidhmchláir agus is féidir í a chomhtháthú le haon chineál feidhmchláir. Soláthraímid samplaí cód chun forbairtóirí a chur ar bun go tapa.
Aspose.Email for Python via .NET features:
• Conversion and rendering of email formats
• Send and receive common emails formats, including attachments
• Download email from IMAP and POP3 mail servers
• Manipulate (create and update) tasks using iCalendar
• Operate message storage files
• Operate email attachments
• Manipulate iCalendar‑compliant meetings or appointments
• TLS and SSL support
• TNEF attachments
Supported file formats:
MSG - Microsoft Outlook and Exchange format for storing email messages, appointments, and similar tasks
PST - Outlook Personal Storage Files for storing emails, calendars, contacts, and other file formats
OST - User’s mailbox data on the local machine after registration with Exchange Server with Microsoft Outlook
OFT - Microsoft Outlook message template files
EML - Email messages saved with Outlook or similar relevant applications
EMLX - Text file developed and implemented by Apple
MBOX - It is used for the collection of electronic mail messages
ICS - iCalendar file format for sharing events and scheduling tasks via emails
VCF - file format for electronic business cards and storing contact information
HTML - HyperText Markup Language extension for web pages and display in browsers
MHTML - this is the archive format and contains the contents of a webpage
Cruthaigh agus socraigh ábhar an ríomhphoist le Python
Create email message
Le rang an MailMessage
is féidir le forbairtóirí teachtaireacht ríomhphoist nua a chruthú. Léiríonn an rang seo teachtaireacht ríomhphoist. Is féidir airíonna ríomhphoist cosúil le Ós, Chuig, Ábhar, agus Corp a chur go héasca leis an teachtaireacht a cruthaítear.
Déanfaimid na céimeanna seo a leanas chun teachtaireacht ríomhphoist nua a chruthú:
- Cruthú sampla den rang MailMessage
- Socrú airíonna an teachtaireachta ríomhphoist
- Sábháil teachtaireachtaí ríomhphoist i bhformáid éagsúla, mar EML, MSG, agus MHTML
Taispeánann an snáipéad cód thíos conas teachtaireacht nua a chruthú le hairíonna éagsúla:
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "New MailMessage created with Aspose.Email for Python"
eml.html_body = "<b>This line is in bold </b> while this is normal text"
eml.from_address = "from@domain.com"
eml.to.append(ae.MailAddress("to1@domain.com", "Recipient 1"))
eml.to.append(ae.MailAddress("to2@domain.com", "Recipient 2"))
eml.cc.append(ae.MailAddress("cc1@domain.com", "Recipient 3"))
eml.cc.append(ae.MailAddress("cc2@domain.com", "Recipient 4"))
#Save generated EML in different formats to disc
eml.save(dataDir + "CreateNewMailMessage_out.eml")
eml.save(dataDir + "CreateNewMailMessage_out.msg", ae.SaveOptions.default_msg_unicode)
eml.save(dataDir + "message_out.msg", ae.SaveOptions.default_msg)
eml.save(dataDir + "message_out.mhtml", ae.SaveOptions.default_mhtml)
eml.save(dataDir + "message_out.html", ae.SaveOptions.default_html)
Setting the HTML body of the message
Le HtmlBody socraímid ábhar HTML an choirp teachtaireachta. Taispeánann an snáipéad cód thíos conas an corp HTML a shocrú:
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Declare message as MailMessage instance
eml = ae.MailMessage()
# Specify HtmlBody
eml.html_body = "<html><body>This is the HTML body</body></html>"
Setting alternate text in the email message
Sonraíonn an rang AlternateView cóipeanna de theachtaireacht ríomhphoist i bhformáid éagsúla, agus tá dhá airí ann:
• LinkedResources, a úsáidtear nuair a rindreofar, a nascann URLanna laistigh den ábhar ríomhphoist le URLanna i gCarraig Nasc na nGnéithe Nascáilte i bhfoireann na nGnéithe Nascáilte
• BaseUri, a úsáidtear ag an léitheoir ríomhphoist chun URLanna coibhneasta sa chorp a réiteach
Tá an cód thíos mar shampla:
# For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Declare message as MailMessage instance
eml = ae.MailMessage()
# Creates AlternateView to view an email message using the content specified in the //string
alternate = AlternateView.create_alternate_view_from_string("Alternate Text")
# Adding alternate text
eml.add_alternate_view(alternate)
Adding an attachment to an email
Rachaidh muid trí na céimeanna seo a leanas chun ceangaltán a chur le ríomhphost:
- Cruthú sampla den rang MailMessage agus Attachment
- Lódáil an ceangaltán sa sampla Attachment
- Cuir an sampla Attachment leis an rang MailMessage
Taispeánann an snáipéad cód thíos sampla de conas ceangaltán a chur le ríomhphost:
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
# Create an instance of MailMessage class
message = MailMessage("sender@domain.com", "receiver@domain.com")
# Load an attachment
attachment = Attachment(dataDir + "1.txt");
# Add Multiple Attachment in instance of MailMessage class and Save message to disk
message.attachments.append(attachment);
message.add_attachment(Attachment(dataDir + "1.jpg"))
message.add_attachment(Attachment(dataDir + "1.doc"))
message.add_attachment(Attachment(dataDir + "1.rar"))
message.add_attachment(Attachment(dataDir + "1.pdf"))
message.save(dataDir + "AddEmailAttachments_out.msg", SaveOptions.default_msg_unicode)
Seol ríomhphost le Python
Ligeann Aspose.Email for Python duit ríomhphoist a sheoladh trí fhreastalaithe SMTP, POP3, agus IMAP. Is féidir leat logáil isteach go héasca ar fhreastalaithe POP3 le d’údarás (ainm úsáideora agus focal faire) nó le fíordheimhniú APOP chun oibríochtaí ríomhphoist a dhéanamh, mar shampla méid an bhosca poist a fheiceáil agus líon na dteachtaireachtaí, an teachtaireacht iomlán nó a cheanntásc a aisghabháil, teachtaireachtaí a scriosadh ón bhfreastalaí, chomh maith le horduithe POP3 bunúsacha.
Tacaíonn Aspose.Email for Python freisin leis an bhprotocol IMAP, lena n-áirítear a chuid horduithe, fíordheimhniú, roghnú, cruthú, scriosadh, fiosrú fillteáin, sábháil teachtaireachtaí, faigh, scrios, agus bainistíocht lipéid.
Sending messages with SMTP client
Chun teachtaireacht ríomhphoist a sheoladh le Python, leanfaidh muid na céimeanna seo a leanas:
- Cruthú sampla den rang MailMessage
- Sonrú na seoltaí ríomhphoist an tseoltóra agus an fhaighteora sa sampla MailMessage
- Sonrú ábhar an TextBody
- Cruthú sampla den rang SmtpClient agus seoladh na teachtaireachta
Taispeánann an snáipéad cód thíos conas ríomhphost téacs a sheoladh le Python:
For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
eml = ae.MailMessage()
eml.subject = "Message with Plain Text Body"
eml.body = "This is plain text body."
eml.from_address = "from@gmail.com"
eml.to.append(ae.MailAddress("to@gmail.com", "Recipient 1"))
#Send using Smtp Client
client = SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = SecurityOptions.AUTO
client.send(eml)
Má theastaíonn cabhair uait le do thionscadal, is féidir leat teagmháil a dhéanamh le ár saineolaithe Paid consulting
i gcónaí. Oibreoidh ár bhfoireann leat an réiteach is fearr a aimsiú do do thionscadal, é a chur i bhfeidhm de réir mar is gá agus an luach is fearr a sholáthar duit. Is féidir leat brath ortas i do fhorbairt agus fás amach amach anseo.