Results 1 to 2 of 2

Thread: Problem with SMTP Client

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2011
    Posts
    75

    Problem with SMTP Client

    Hi All,

    Im trying to configure a email within .net i have 5 varibles which im putting in to the email which are (EmailFrom, NewUserEmail, EmailSubject, EmailBody, EmailFromName) my ObjMailMessage accepts the first 4 but when i add the last one EmailFromName it throws an error which is "Overload resolution failed because no accessible 'New' accepts this number of arguments"

    So im kinda puzzled on how i can get this to work because i need to send a email with the 5 varibles passed in, later on down the line this may increase to at least 7-10 heres my code

    First part is the Email

    Code:
           Try
                FromUserEmail = FromEmail
                ToUserEmail = ToEmail
                QuestionMessage = Message
                EmailFromName = FromName
    
                Dim ReturnText As String = String.Empty
                EmailSubject = "Email Regarding Item: " & ItemTitle
                EmailBody = "<html><head><title>ChaucerAuction - Auction Email</title>"
                EmailBody &= "<link href='#' type='text/css'rel='stylesheet' />"
                EmailBody &= " </head><body><div align='right'><img src='#'/>"
                EmailBody &= "</div><div align='left' style='margin-left:40px; margin-top:10px' class='emailtext'>"
                EmailBody &= "Hi " & OwnerName & _
                                         "<br/><br/>Just a quick email to find out: <br/><br/><b> " & _
                                         Message & ".</b><br/><br/>" & _
                                         "Kind Regards<a class='menuItem' " & _
                                          FromName & _
                                         "<br/><br/>" & _
                                         "<br/><br/>"
                EmailBody &= "</div></body></html>"
                Send()
    
            Catch ex As Exception
                ErrorText &= "An error has occurred in Email.Send : " & ex.Message & vbCrLf
            End Try
    heres the Send Method where the error is shown

    Code:
      Public Sub Send()
            Try
                Dim objMailMessage As New MailMessage(EmailFrom, NewUserEmail, EmailSubject, EmailBody, EmailFromName)
                objMailMessage.IsBodyHtml = True
    
                'Send message
                Dim SmtpClient As New Net.Mail.SmtpClient("SMTPServer")
                SmtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
                SmtpClient.UseDefaultCredentials = True
                SmtpClient.Send(objMailMessage)
    
            Catch ex As Exception
                ErrorText &= "An error has occurred in Email.Send : " & ex.Message & vbCrLf
            End Try
        End Sub
    And there declared like this

    Code:
        Private FromUserEmail As String = String.Empty
        Private ToUserEmail As String = String.Empty
        Private Private EmailSubject As String = String.Empty
        Private EmailBody As String = String.Empty
        Private EmailFromName As String = String.Empty
    Im stumped

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Problem with SMTP Client

    The issues is simple. There is no constructor that accepts 5 strings. You are trying to use this one: MailMessage Constructor (String, String, String, String) by specifying 5 strings. Obviously that won't work. I would suggest using this constructor: MailMessage Constructor (MailAddress, MailAddress) like so:
    Code:
    Dim message = New MailMessage(New MailAddress(fromEmail, fromDisplayName), _
                                  New MailAddress(toEmail))
    message.Subject = subject
    message.Body = body
    message.IsBodyHtml = True

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