Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMTP e-mail 2008 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
0
0
US
Hi all:

I'm using a procedure provided by Microsoft that appears to work, but it doesn't send anything.

This is a slightly modified MS sub; I added port and type sent.

Code:
Public Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, _
        ByVal subject As String, ByVal body As String)
        ' Instantiate a new instance of MailMessage
        Dim mMailMessage As New MailMessage()

        ' Set the sender address of the mail message
        mMailMessage.From = New MailAddress(from)
        ' Set the recepient address of the mail message
        mMailMessage.To.Add(New MailAddress(recepient))

        ' Check if the bcc value is null or an empty string
        If Not bcc Is Nothing And bcc <> String.Empty Then
            ' Set the Bcc address of the mail message
            mMailMessage.Bcc.Add(New MailAddress(bcc))
        End If

        ' Check if the cc value is null or an empty value
        If Not cc Is Nothing And cc <> String.Empty Then
            ' Set the CC address of the mail message
            mMailMessage.CC.Add(New MailAddress(cc))
        End If

        ' Set the subject of the mail message
        mMailMessage.Subject = subject
        ' Set the body of the mail message
        mMailMessage.Body = body

        ' Secify the format of the body as HTML
        mMailMessage.IsBodyHtml = True
        ' Set the priority of the mail message to normal
        mMailMessage.Priority = MailPriority.Normal

        ' Instantiate a new instance of SmtpClient
        Dim mSmtpClient As New SmtpClient()
''I added this
        [b]mSmtpClient.Host = "RepProductions"
        mSmtpClient.Port = 995
        mSmtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis[/b]
''to here
        ' Send the mail message
        mSmtpClient.Send(mMailMessage)
        MessageBox.Show("Sent")
    End Sub

Am I missing something?

Thanks,



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Sorry, this is the one from MS:

Code:
Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click

        If ToAddress.Text = "" Or From.Text = "" Then
            MsgBox("You must enter both To and From email addresses.")
            Exit Sub
        End If

        ' Use the StringBuilder class instead of traditional string concatenation.
        ' It is optimized for building strings because it is capable of modifying
        ' the underlying buffer instead of having to make a copy of the string for 
        ' each concatenation.
        Dim sb As New StringBuilder()

        ' Build the email message body.
        sb.Append("The following email was sent to you from the Send Mail " & _
            "sample application:")
        sb.Append(vbCrLf)
        sb.Append(vbCrLf)
        sb.Append("SUBJECT: ")
        sb.Append(Trim(Subject.Text))
        sb.Append(vbCrLf)
        sb.Append(vbCrLf)
        sb.Append("MESSAGE: ")
        sb.Append(Trim(Body.Text))
        sb.Append(vbCrLf)

        ' Creating a mail message is as simple as instantiating a class and 
        ' setting a few properties.
        Dim mailMsg As New MailMessage(From.Text.Trim, ToAddress.Text.Trim)
        With mailMsg
            If Not String.IsNullOrEmpty(CC.Text) Then
                .CC.Add(New MailAddress(CC.Text.Trim))
            End If

            If Not String.IsNullOrEmpty(BCC.Text) Then
                .Bcc.Add(New MailAddress(BCC.Text.Trim))
            End If

            .Subject = Subject.Text.Trim
            .Body = sb.ToString

            If Not IsNothing(arlAttachments) Then
                Dim mailAttachment As Attachment
                For Each mailAttachment In arlAttachments
                    .Attachments.Add(mailAttachment)
                Next
            End If
        End With

        ' Set the SmtpServer name. This can be any of the following depending on
        ' your local security settings:

        ' a) Local IP Address (assuming your local machine's SMTP server has the 
        ' right to send messages through a local firewall (if present).

        ' b) 127.0.0.1 the loopback of the local machine.

        ' c) "smarthost" or the name or the IP address of the exchange server you 
        ' utilize for messaging. This is usually what is needed if you are behind
        ' a corporate firewall.

        ' Use structured error handling to attempt to send the email message and 
        ' provide feedback to the user about the success or failure of their 
        ' attempt.
        Try
            Dim client As New SmtpClient("127.0.0.1")
            client.Port = 110
            'client.Credentials.GetCredential("Repproductions", 995, "Good2Dogs@SBCGlobal.net")


            client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
            client.Send(mailMsg)
            Attachments.Items.Clear()
            Attachments.Items.Add("(No Attachments)")

            MessageBox.Show("Your email has been successfully sent!", _
                "Email Send Status", MessageBoxButtons.OK, _
                MessageBoxIcon.Information)
        Catch exp As Exception
            MessageBox.Show("The following problem occurred when attempting to " & _
                "send your email: " & exp.Message, _
                Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Have you checked the log for the SMTP host "RepProductions"?

This will tell you whether the message was received and sent. You may have to turn logging on as it's often not enabled. It's also possible the the host smtp service is actually stopped.

Bob Boffin
 
Hi Bob:

Thanks for the reply.

Although I could not find where to turn on/off a log, I followed it to inetpub\mailroot\queue.

There I found all the "failures".

Any suggestions on how to make this work?

Or, a better code to go through Exchange, if necessary.

Thanks...and a star.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top