locked
Expressions Help RRS feed

  • Question

  • When I use this line I keep getting a "Expression Expected" error. I don't know what to do.

    Email.Attachments() = {ReadOnlyException}(Me)

     
    Me
    Tuesday, July 8, 2008 8:56 PM

Answers

  • sqwirllover said:

    When I use this line I keep getting a "Expression Expected" error. I don't know what to do.

    Email.Attachments() = {ReadOnlyException}(Me)

    Hi sqwirllover,

    I presume that you want to send email containing attachment in VB.NET, then please check the following code sample:

    Imports System.Net.Mail  
     
    Public Class Form1  
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click  
     
            Dim email As MailMessage = New MailMessage("FromMailAdress""ToMailAdress""Subject""Body")  
     
            ' Add attachments to the mail like this:  
            email.Attachments.Add(New Attachment("D:\filename.doc"))  
     
            Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host  
     
            mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout""Password")  
     
            mailSenderInstance.Send(email)  
            email.Dispose() ' remember to dispoae the object  
        End Sub 
     
    End Class 

    Check this thread for several approaches to sending email:
    http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2417150&SiteID=1


    Best regards,
    Martin Xie

    Monday, July 14, 2008 9:19 AM