It is strongly recommended that you actually try to create the application before asking questions. Vague questions are very hard to answer.
If you start by trying to send an email, as described by that article, and then get back to us with more specific questions on the problems you're encountering we will be able to better help you.
(I realize that the article is written for VB.NET applications. But you should be able to easily use it in your C# application with a few syntactical changes. )
Partial Class _Default
Inherits System.Web.UI.P age
Dim sTo As String, sFrom As String, sSubject As String, sBody As String
Dim sAttach As String, sCc As String, sBcc As String, sBodyEncoding As String
Dim sBodyFormat As String, sMailServer As String, sPriority As String
Dim sUrlContentBase As String, sUrlContentLoca tion As String
Dim iLoop1 As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
Dim Encoding As New System.Net.Mail .MailMessage
If Not IsPostBack Then
lblMsg1.Text = ""
txtTo.Text = "palanivels@red iffmail.com.com "
txtFrom.Text = "marsha@contoso .com"
txtCc.Text = "fred@contoso.c om"
txtBcc.Text = "wilma@contoso. com"
txtSubject.Text = "Hello"
txtBody.Text = "This is a test message."
'txtAttach.Text = "C:\Documen ts and Settings\All Users\Documents \My Pictures\Sample Pictures\Sunset .jpg," _
' & "C:\Documen ts and Settings\All Users\Documents \My Pictures\Sample Pictures\Winter .jpg"
' txtBodyEncoding .Text = Encoding.ASCII. EncodingName
txtBodyFormat.T ext = "HTML"
txtPriority.Tex t = "Normal"
txtUrlContentBa se.Text = "http://www.contoso.com/images"
txtUrlContentLo cation.Text = "http://www.contoso.com/images"
' Name of relay mail server in your domain.
txtMailServer.T ext = "smarthost" '
End If
End Sub
Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click
Dim sTo As String, sFrom As String, sSubject As String, sBody As String
Dim sAttach As String, sCc As String, sBcc As String, sBodyEncoding As String
Dim sBodyFormat As String, sMailServer As String, sPriority As String
Dim sUrlContentBase As String, sUrlContentLoca tion As String
' Dim iLoop1 As Integer
Dim MyMail As Mail.MailMessag e = New Mail.MailMessag e
MyMail.From = sFrom
MyMail.To = sTo
MyMail.Subject = sSubject
MyMail.Body = sBody
MyMail.Cc = sCc
MyMail.Bcc = sBcc
MyMail.UrlConte ntBase = sUrlContentBase
MyMail.UrlConte ntLocation = sUrlContentLoca tion
Select Case txtBodyEncoding .Text
Case Encoding.UTF7.E ncodingName : MyMail.BodyEnco ding = Encoding.UTF7
Case Encoding.UTF8.E ncodingName : MyMail.BodyEnco ding = Encoding.UTF8
Case Else : MyMail.BodyEnco ding = Encoding.ASCII
End Select
Select Case UCase(sBodyForm at)
Case "HTML" : MyMail.BodyForm at = Mail.MailFormat .Html
Case Else : MyMail.BodyForm at = Mail.MailFormat .Text
End Select
Select Case UCase(sPriority )
Case "HIGH" : MyMail.Priority = Mail.MailPriori ty.High
Case "LOW" : MyMail.Priority = Mail.MailPriori ty.Low
Case Else : MyMail.Priority = Mail.MailPriori ty.Normal
End Select
'Build an IList of mail attachments.
If sAttach <> "" Then
Dim delim As Char = ","
Dim sSubstr As String
For Each sSubstr In sAttach.Split(d elim)
Dim myAttachment As Net.Mail.Attach ment = New Net.Mail.Attach ment(sSubstr)
MyMail.Attachme nts.Add(myAttac hment)
Next
End If
This is a network related error. Your application cannot connect to the mail server specified.
SmtpMail.SmtpSe rver
Is a valid SMTP Server?
Check to be sure the server System.Web.Mail is executing on can connect to the mail server. Some times firewalls or proxy servers can get in the way.
Try specifying the value by IP address. Poor DNS resolution can sometimes hinder name lookups.
Make sure the that the mail server is running at port 25.
If you did not specify a SmtpMail.SmtpSe rver property, or if SmtpMail.SmtpSe rver points to "localhost" (or the equivalent), be sure the SMTP Service is running on port 25.
For testing purposes change the MailMessage.Fro m and MailMessage.To properties to an address that exists on SmtpMail.SmtpSe rver. Some times this exception is thrown, when it really is a relay issue.
Comment