לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ברוכים הבאים לפורום ASP חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > ASP
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
 
כלי אשכול חפש באשכול זה



  #6  
ישן 14-11-2004, 11:27
צלמית המשתמש של fat fish
  fat fish fat fish אינו מחובר  
 
חבר מתאריך: 20.06.03
הודעות: 5,616
להלן המאמר בנושא:
בתגובה להודעה מספר 5 שנכתבה על ידי רחלי22 שמתחילה ב "ממש לא עצלנית"

Sending a Simple E-Mail Message


To send an e-mail with a simple text message, you have to use the Send() method of SMTP class. The syntax of the Send() method is shown in Listing 1.1 and an example is shown in Listing 1.2:

Listing 1.1

[Visual C# .NET]

קוד:
SmtpMail.Send("FROM","TO","SUBJECT","MESSAGE BODY");

[Visual Basic .NET]

קוד:
SmtpMail.Send("FROM","TO","SUBJECT","MESSAGE BODY")

Listing 1.2

[Visual C# .NET]

קוד:
SmtpMail.Send("info@mydomain.com","hello@hello.com","Thank You", "We look forward to working with you again in the future");

[Visual Basic .NET]

קוד:
SmtpMail.Send("info@mydomain.com","hello@hello.com","Thank You", _ "We look forward to working with you again in the _ future")

You can place the above code either on the form's Load() event or in a button control.

Sending E-Mail Messages Using WebForm Controls

The main problem with the code given in Listing 1.2 is that you have to change the parameter values each time for sending different mail messages. To solve this problem, you should build a User Interface using the required WebForm controls, as shown in Figure 1.



תמונה שהועלתה על ידי גולש באתר ולכן אין אנו יכולים לדעת מה היא מכילה
Figure 1: The User Interface

As you can see, the above User Interface is made up of two text boxes, one multiline text box, and a button. I have also applied ASP.NET validation controls to the above GUI to avoid errors.


Instead of supplying all parameters in the Send() method, you can define properties and their corresponding values separately by creating an instance of the MailMessage class. With the help of this class, you can easily add attachments, set priorities, BCC, CC values, and much more. Table 1, given at the end of this article, shows a list of properties of the MailMessage class. Add the code given in Listing 1.3 by double-clicking the button captioned Submit:

Listing 1.3

[Visual C# .NET]

קוד:
MailMessage objEmail = new MailMessage(); objEmail.To = txtTo.Text; objEmail.From = txtFrom.Text; objEmail.Cc = txtCc.Text; objEmail.Subject = "Test Email"; objEmail.Body = txtName.Text + ", " + txtComments.Text; objEmail.Priority = MailPriority.High; //SmtpMail.SmtpServer = "localhost"; try{ SmtpMail.Send(objEmail); Response.Write("Your Email has been sent sucessfully - Thank You"); } catch (Exception exc){ Response.Write("Send failure: " + exc.ToString()); }

[Visual Basic .NET]

קוד:
Dim objEmail as New MailMessage() objEmail.To = txtTo.Text objEmail.From = txtFrom.Text objEmail.Cc = txtCc.Text objEmail.Subject = "Test Email" objEmail.Body = txtName.Text & ", " &txtComments.Text objEmail.Priority = MailPriority.High 'SmtpMail.SmtpServer = "localhost" try SmtpMail.Send(EMail) Response.Write(Your E-mail has been sent sucessfully - _ Thank You) catch exc as Exception Response.Write("Send failure: " + exc.ToString()) End Try

Note: If you are using your local system (Server = localhost) instead of a real live server, you should properly enable relying on the Internet Information Server (IIS).
When you execute the above code, the server not only displays a confirmation message but also sends an e-mail to the address mentioned in the To and Cc text boxes with the information you entered in the respective fields. It is not necessary for you to enter a Cc address, but it is shown here as part of the explanation. Further, the e-mail will be sent with the highest priority.

Sending HTML E-Mail Messages

If you would like to send the above e-mail in HTML Format, simply add the code given below to the above listing:

[Visual C# .NET]

קוד:
objEmail.BodyFormat = MailFormat.Html;

[Visual Basic .NET]

קוד:
objEmail.BodyFormat = MailFormat.Html





_____________________________________
[ זיו ]
[ fat fish ]

חזרה לפורום
  #8  
ישן 14-11-2004, 07:23
  רחלי22 רחלי22 אינו מחובר  
 
חבר מתאריך: 30.05.04
הודעות: 34
עזרה בפיענוח
בתגובה להודעה מספר 1 שנכתבה על ידי רחלי22 שמתחילה ב "שליחת דואר"

מצאתי קוד באחד האתרים לשליחת מייל מישהוא אולי יכל לתת לי הסבר מה אני צריכה לשנות לפי ההגדרות שיתאימו לי ואיך אני נותנת פקודה שהמייל ילקח מהעמודה הספציפית ששם נישמר האמייל בדטאבייס שנשלח ע"י הנרשם בתהליך הרישום:
<html><head>
<title>serverobjectsmail.asp</title>

</head><body bgcolor="#FFFFFF">
<%
' ASPMail(tm) from www.serverobjects.com
' is not part of ASP per se,
' but a third party utility from serverobjects.com
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "localhost"
Mailer.qmessage=true
Mailer.FromName = "Some Student"
Mailer.FromAddress = "somestudent@activeserverpages.com"
Mailer.AddRecipient "Charles Carroll","selfdestruct@learnasp.com"
Mailer.AddBCC "Sally Jones","selfdestruct@learnasp.com"
Mailer.Subject = "ASPMail Tutorial"

Mailer.BodyText = "Hi. Just trying the mail example" & vbCrLf
Mailer.BodyText = "Line 2"
Mailer.BodyText = "Line 3"
If Mailer.SendMail then
Msg = "mail sent sucessfully!"
Else
Msg = "mail <b>not</b> sent sucessfully"
msg = msg & "<br>" & mailer.response
End If
response.write Msg

set mailer=nothing
%>

</body></html>
חזרה לפורום

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 19:08

הדף נוצר ב 0.06 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר