Αποστολή e-mail από φόρμες με SMTP authentication - ASP.NET
Προβολές: 4926 Τελευταία ενημέρωση: 04/09/2017 12:40 | 0 Βαθμολογία/ Χρήστες |
![]() ![]() ![]() ![]() ![]() |
Για να στείλετε email από την φόρμα επικοινωνίας ή παραγγελίας του ASP.NET website σας, τότε θα πρέπει να χρησιμοποιήσετε τη μέθοδο του SMTP Authentication.
Έτσι ο server μας θα επαληθεύσει ότι η φόρμα σας έχει το δικαίωμα να στείλει email διαμέσω του server και θα της επιτρέψει την αποστολή του email στον/στους παραλήπτη/τες που θα ορίσετε.
Αυτό μπορείτε να το πετύχετε με το System.Net.Mail είναι το namespace που χρησιμοποιείται για την αποστολή email, αν έχετε .NET Framework 2.0 (ή νεότερη έκδοση).
Απλά εισάγετε τον παρακάτω κώδικα σε ένα αρχείο mail.aspx και αλλάξτε τις ρυθμίσεις έτσι ώστε να συμφωνούν με τις ρυθμίσεις του Server σας.
Language C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.Net.Mail" %> <script language="C#" runat="server"> protected void Page_Load(object sender, EventArgs e) { MailMessage mail = new MailMessage(); mail.From = new MailAddress ( "sender@domain.tld" ); mail.Subject = "This is a test message" ; mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "If you can see this mail, your SMTP service is working" ; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.To.Add( "receiver@domain.tld" ); SmtpClient smtp = new SmtpClient( "mail.domain.tld" ); NetworkCredential credential = new NetworkCredential ("auth_user@domain.tld" , "***********"); smtp.Credentials = credential; smtp.Port = 587; smtp.Send(mail);} </script> |
----------------------------------
Language VB.net
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<%@ Page Language="VB" %> <%@ Import Namespace="System.Net.Mail" %> <script runat="server"> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim strFrom = "sender@domain.tld" ''IMPORTANT: This must be same as your smtp authentication address. Dim strTo = "receiver@domain.tld" Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo)) MailMsg.BodyEncoding = Encoding.Default MailMsg.Subject = "This is a test" MailMsg.Body = "This is a sample message using SMTP authentication" MailMsg.Priority = MailPriority.High MailMsg.IsBodyHtml = True 'Smtpclient to send the mail message Dim SmtpMail As New SmtpClient Dim basicAuthenticationInfo As New System.Net.NetworkCredential("auth_user@domain.tld", "***********") ''IMPORANT: Your smtp login email MUST be same as your FROM address. SmtpMail.Host = "mail.domain.tld" SmtpMail.UseDefaultCredentials = False SmtpMail.Credentials = basicAuthenticationInfo SmtpMail.Send(MailMsg) lblMessage.Text = "Mail Sent" End Sub </script> <html> <body> <form runat="server"> <asp:Label id="lblMessage" runat="server"></asp:Label> </form> </body> </html> |
Έτσι λοιπόν γίνεται το SMTP Authentication μέσα από σελίδες ASP.ΝΕΤ
Σχετικά Άρθρα
- WordPress, Aποστολή e-mail με SMTP authentication
- Αποστολή e-mail από φόρμες επικοινωνίας με SMTP authentication
- Λαμβάνω επιστροφή μηνύματος με σφάλμα: 553 sorry, that domain isn't in my list of allowed rcpthosts 5.7.1
- Ρύθμιση email στο Outlook, Τhunderbird κ.α.
- Έλεγχος εισερχομένων στο SpamFilter
- Δημιουργία Nameservers για VPS ή Dedicated Servers hosting
- Σύνδεση domain με το weebly.com site σας
- Tι είναι το SSL;
- Σύνδεση domain name με το wordpress.com blog σας
- Aνακατεύθυνση domain στο κεντρικό site σας (domain alias)