Results 1 to 13 of 13

Thread: E-mailing in .NET ...code problem [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    8

    Exclamation E-mailing in .NET ...code problem [RESOLVED]

    Hi There.

    I'm developing this program that lets the user easily send e-mail to a recipient. All of the concept is there, but my code needs a little bit of editing. I'll outline the problems for you once you can take a look at the code. By the way, sorry if there's obvious mistakes...It's late at night and I don't feel well, so cut me some slack:P. And I know this might take a lot of reading through to fix some errors, but I appreciate your time.

    Screenshot:



    VB Code:
    1. Imports System.Web.Mail
    2.  
    3. ' Variable which will send the mail
    4. Dim obj As System.Web.Mail.SmtpMail
    5.  
    6. 'Variable to store the attachments
    7. Dim Attachment As System.Web.Mail.MailAttachment
    8.  
    9. 'Variable to create the message to send
    10. Dim Mailmsg As New System.Web.Mail.MailMessage()
    11. Public Class Form1
    12.  
    13.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    14.  
    15.     End Sub
    16.  
    17.     Private Sub cmdAddAttach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddAttach.Click
    18.         'Show open dialogue box to select the files to attach
    19.         Dim Counter As Integer
    20.         OFD.CheckFileExists = True
    21.         OFD.Title = "Select file(s) to attach."
    22.         OFD.ShowDialog()
    23.  
    24.         For Counter = 0 To UBound(OFD.FileNames)
    25.             lstAttachment.Items.Add(OFD.FileNames(Counter))
    26.         Next
    27.     End Sub
    28.  
    29.     Private Sub cmdRemoveAttach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemoveAttach.Click
    30.         If lstAttachment.SelectedIndex > -1 Then
    31.             lstAttachment.Items.RemoveAt(lstAttachment.SelectedIndex)
    32.         End If
    33.     End Sub
    34.  
    35.     Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
    36.         Dim Counter As Integer
    37.  
    38.         'Validate the data
    39.         If txtSMTPServer.Text = "" Then
    40.             MsgBox("Enter the SMTP server info ...!!!", MsgBoxStyle.Information, "Send Email")
    41.             Exit Sub
    42.         End If
    43.  
    44.         If txtFromEmail.Text = "" Then
    45.             MsgBox("Enter your Email address.", MsgBoxStyle.Information, "Send Email")
    46.             Exit Sub
    47.         End If
    48.  
    49.         If txtTo.Text = "" Then
    50.             MsgBox("Enter the Recipient's Email address.", MsgBoxStyle.Information, "Send Email")
    51.             Exit Sub
    52.         End If
    53.  
    54.         If txtSubject.Text = "" Then
    55.             MsgBox("Please enter an e-mail subject.", MsgBoxStyle.Information, "Send Email")
    56.             Exit Sub
    57.         End If
    58.  
    59.         'Set the properties
    60.         'Assign the SMTP server
    61.         obj.SmtpServer = txtSMTPServer.Text
    62.         'Multiple recepients can be specified using ; as the delimeter
    63.         'Address of the recipient
    64.         Mailmsg.To = txtTo.Text
    65.  
    66.  
    67.         'Your From Address
    68.         'You can also use a custom header Reply-To for a different replyto address
    69.         Mailmsg.From = "\" & txtFromName.Text & "\ <" & txtFromEmail.Text & ">"
    70.  
    71.  
    72.         'Specify the body format
    73.         If chkFormat.Checked = True Then
    74.             Mailmsg.BodyFormat = MailFormat.Html   'Send the mail in HTML Format
    75.         Else
    76.             Mailmsg.BodyFormat = MailFormat.Text
    77.         End If
    78.  
    79.         'If you want you can add a reply to header
    80.         'Mailmsg.Headers.Add("Reply-To", "[email protected]")
    81.         'custom headersare added like this
    82.         'Mailmsg.Headers.Add("Manoj", "TestHeader")
    83.  
    84.         'Mail Subject
    85.         Mailmsg.Subject = txtSubject.Text
    86.  
    87.         'Attach the files one by one
    88.         For Counter = 0 To lstAttachment.Items.Count - 1
    89.             Attachment = New MailAttachment(lstAttachment.Items(Counter))
    90.             'Add it to the mail message
    91.             Mailmsg.Attachments.Add(Attachment)
    92.         Next
    93.  
    94.         'Mail Body
    95.         Mailmsg.Body = txtMessage.Text
    96.         'Call the send method to send the mail
    97.         obj.Send(Mailmsg)
    98.     End Sub
    99. End Class

    Ok. Here's a list of the errors I'm getting:

    1. It is saying that the following is not in a valid namespace:

    VB Code:
    1. Imports System.Web.Mail
    2.  
    3. ' Variable which will send the mail
    4. Dim obj As System.Web.Mail.SmtpMail
    5.  
    6. 'Variable to store the attachments
    7. Dim Attachment As System.Web.Mail.MailAttachment
    8.  
    9. 'Variable to create the message to send
    10. Dim Mailmsg As New System.Web.Mail.MailMessage()

    2. It says that the Namespace or type specified in the Imports "System.Web.Mail" cannot be found.

    3. The name "obj" is not declared. What would I declare it as, and where?

    4. The name "Mailmsg" is not declared. What would I declare it as, and where?

    5. The name "MailFormat is not declared. What would I declare is as, and where?

    6. The name "Attachment" is not declared. What would I declare it as, and where?

    7. Finally, the name "MailAttachment" is not declared. What would I declare it as, and where?


    ----------

    Can anyone help me? Thanks!

    -742617000027
    Last edited by 742617000027; Jun 15th, 2005 at 02:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width