ASP.NET Web Pages - Αντικείμενο WebMail
- Προηγούμενη σελίδα Βάση Δεδομένων WebPages
- Επόμενη σελίδα Βοηθός WebPages
Με τον αντικείμενο WebMail, μπορείτε εύκολα να στείλετε ηλεκτρονικά μηνύματα από την ιστοσελίδα.
Description
WebMail παρέχει μέθοδο για τη δημιουργία και αποστολή ηλεκτρονικών μηνυμάτων μέσω του απλού protokόλου μεταφοράς μηνυμάτων (SMTP).
範例
参閱 Web Pages Email The example in this chapter.
WebMail Object Reference Manual - Property
Property | Description |
---|---|
EnableSsl | True if the server uses SSL encryption. |
From | Gets or sets the sender's email address. |
Password | Gets or sets the password for the sender's email account. |
SmtpPort | Gets or sets the port used for SMTP transactions. |
SmtpServer | Gets or sets the name of the SMTP server used to deliver emails. |
UserName | Gets or sets the email account name used to send emails. |
WebMail Reference Manual - Method
Method | Description |
---|---|
Send() | Sends the specified email to the SMTP server for delivery. |
The Send() method has the following parameters:
Parameters | Type | Description |
---|---|---|
to | String | The recipient's email address. Separated by a semicolon (;). |
subject | String | The subject line. |
body | String | The body of the email. |
And the following optional parameters:
Parameters | Type | Description |
---|---|---|
from | String | The sender's email address. |
cc | String | The addresses to which the email will be carbon copied; separated by a semicolon (;). |
filesToAttach | Collection | A collection of filenames used to specify the files to be attached to the email. |
isBodyHtml | Logical value | If true, specifies that the email body is in HTML format. |
additionalHeaders | Collection | A collection of headers that can be added to the normal SMTP headers included in this email. |
bcc | String | The email addresses of the other recipients to whom a 'blind carbon copy' of the email will be sent. |
contentEncoding | String | The encoding used for the email body. |
headerEncoding | String | The encoding used for the email header. |
priority | String | The value used to specify the email priority. |
replyTo | String | The email address that will be used when the recipient replies to the email. |
Technical data
Name | Value |
---|---|
Class | System.Web.Helpers.WebMail |
Namespace | System.Web.Helpers |
Assembly | System.Web.Helpers.dll |
Για να χρησιμοποιήσετε τον βοηθό WebMail, πρέπει να επισκεφθείτε έναν SMTP διακομιστή. Το SMTP είναι η
Για να στείλετε email, χρειάζεστε:
- Όνομα διακομιστή SMTP
- Πόρτα (συνήθως 25)
- Όνομα χρήστη email
- Κωδικός πρόσβασης email
Στο φάκελο ρίζας του ιστοτόπου, δημιουργήστε (ή επεξεργαστείτε) μια σελίδα με το όνομα _AppStart.cshtml:
Γράψτε τον παρακάτω κώδικα στο αρχείο:
_AppStart.cshtml
@} WebMail.SmtpServer = "smtp.example.com"; WebMail.SmtpPort = 25; WebMail.EnableSsl = false; WebMail.UserName = "support@example.com"; WebMail.Password = "password"; WebMail.From = "john@example.com" }
Ο κώδικας παρακάτω θα εκτελεστεί κάθε φορά που ξεκινά το ιστοσελίδα (εφαρμογή). Θα επηρεάσει Το αντικείμενο WebMailΓια την εκκίνηση.
Παρακαλώ αντικαταστήστε:
smtp.example.com Για το όνομα του διακομιστή SMTP που θα χρησιμοποιηθεί για την αποστολή email.
25 Για τον αριθμό του θύρα που θα χρησιμοποιηθεί από τον διακομιστή για την επεξεργασία SMTP (email).
false Για true, αν ο διακομιστής χρησιμοποιεί ασφαλή σύνδεση σύνδεσης (SSL) για την κρυπτογράφηση της σύνδεσης κατά την αποστολή email.
support@example.com Για το όνομα του λογαριασμού email που χρησιμοποιείται για την αποστολή email.
password Για τον κωδικό πρόσβασης του λογαριασμού SMTP email.
john@example Για την διεύθυνση του αποστολέα.
Συμβουλή:Δεν πρέπει ναinizializeτε το αντικείμενο WebMail στο αρχείο AppStart, αλλά πρέπει να ρυθμίσετε αυτές τις ιδιότητες πριν από την κλήση του μεθόδου WebMail.Send().
- Προηγούμενη σελίδα Βάση Δεδομένων WebPages
- Επόμενη σελίδα Βοηθός WebPages