uot;"
Try
strPath = Path.GetFullPath(postedFile.FileName)
Catch
End Try
Now for the real work. For the most part properties of the MailMessage object (objMail) are being set to the contents of the textboxes and the message priority DropDownListBox. Notice again that the attachment object (objAttach) and the objMail.Attachements.Add are set within a Try-Catch block. Once again this is to protect against the possibility that no attachment is being sent. objMail.From = txtFrom.Text
objMail.To = txtTo.Text
objMail.Subject = txtSubject.Text
objMail.Body = txtMessage.Text
If ddlPriority.SelectedItem.Text = "Low" Then
objMail.Priority = MailPriority.Low
ElseIf ddlPriority.SelectedItem.Text = "Normal" Then
objMail.Priority = MailPriority.Normal
Else
objMail.Priority = MailPriority.High
End If
objMail.Cc = txtCC.Text
objMail.Bcc = TxtBCC.Text
Try
objAttach = New MailAttachment(strPath)
objMail.Attachments.Add(objAttach)
Catch
End Try
objConn.Send(objMail)
End Sub
End Class
Conclusion: You have just seen most of the properties and methods of the Mail and Smtp objects at work.
Try
strPath = Path.GetFullPath(postedFile.FileName)
Catch
End Try
Now for the real work. For the most part properties of the MailMessage object (objMail) are being set to the contents of the textboxes and the message priority DropDownListBox. Notice again that the attachment object (objAttach) and the objMail.Attachements.Add are set within a Try-Catch block. Once again this is to protect against the possibility that no attachment is being sent. objMail.From = txtFrom.Text
objMail.To = txtTo.Text
objMail.Subject = txtSubject.Text
objMail.Body = txtMessage.Text
If ddlPriority.SelectedItem.Text = "Low" Then
objMail.Priority = MailPriority.Low
ElseIf ddlPriority.SelectedItem.Text = "Normal" Then
objMail.Priority = MailPriority.Normal
Else
objMail.Priority = MailPriority.High
End If
objMail.Cc = txtCC.Text
objMail.Bcc = TxtBCC.Text
Try
objAttach = New MailAttachment(strPath)
objMail.Attachments.Add(objAttach)
Catch
End Try
objConn.Send(objMail)
End Sub
End Class
Conclusion: You have just seen most of the properties and methods of the Mail and Smtp objects at work.
| 对此文章发表了评论 |

