Hi all,

Thanks for the support u have given till now.I had a confusion in sending email like

I have created a button for email and i want to send the text which is in a textbox iam using " Me.mapiSession.SignOn() " code for sending but i have missed some thing its not working. Can u help please. iam using .NET 2005 for this code.
System : windows XP serice pack 2
IIS Installed On my system

Hope a soon reply.
Thanks and regards

Dani AI

Generated

Thread context: tried a MAPI-based sign-on from a VB.NET app on Windows XP and reported it failing; pointed toward using System.Net.Mail instead. Two quick clarifications: MAPI-based calls require a local MAPI client (Outlook) and an interactive profile, and are not appropriate for server-side or IIS-hosted code. For a reliable programmatic send from a .NET app, send through an SMTP server (System.Net.Mail in .NET Framework or a modern library such as MailKit) rather than automating MAPI.

A minimal VB.NET pattern that shows the missing pieces (host, port, credentials, SSL, and proper disposal):

Imports System.Net
Imports System.Net.Mail

Sub SendTest()
    Using msg As New MailMessage()
        msg.From = New MailAddress("sender@example.com")
        msg.To.Add("recipient@example.com")
        msg.Subject = "Test"
        msg.Body = "Hello"

        Using smtp As New SmtpClient("smtp.example.com", 587)
            smtp.EnableSsl = True
            smtp.Credentials = New NetworkCredential("smtpuser", "smtppass")
            smtp.Send(msg)
        End Using
    End Using
End Sub

Troubleshooting checklist (common gaps seen in the thread):

  • If the code uses "localhost" as the SMTP host, confirm a real SMTP relay is installed and running. Many client OS installs do not provide an SMTP server by default.
  • Test connectivity from the machine (telnet smtp.example.com 25/587) to rule out firewall/ISP blocking.
  • Verify correct port and SSL settings (e.g., port 587 + STARTTLS). For providers like Gmail, application-specific passwords or OAuth are now required.
  • Capture and log SmtpException and InnerException to see SMTP response codes.
  • Never automate Outlook on a web server or in IIS — Microsoft advises against server-side Office automation.

Further reading: Microsoft guidance on sending mail from .NET and on server-side Office automation. For modern projects consider MailKit for robust SMTP/IMAP/POP support.

You can try this code:::


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text)

If txtFrom.Text.Trim() = "" Then
MessageBox.Show("Enter the From address.", "Email Error", MessageBoxButtons.OK, _
MessageBoxIcon.Stop)
txtFrom.Focus()
Exit Sub
End If

If txtTo.Text = "" Then
MessageBox.Show("Enter the Recipient address(es).", "Email Error", _
MessageBoxButtons.OK, MessageBoxIcon.Stop)
txtTo.Focus()
Exit Sub
End If

If txtSubject.Text = "" Then
MessageBox.Show("Enter the subject.", "Email Error", MessageBoxButtons.OK, _
MessageBoxIcon.Stop)
txtSubject.Focus()
Exit Sub
End If

Try

Dim emailClient As New SmtpClient(lblHost.Text)
Dim attachFile As New Attachment("k:\doc\DOCUMENTATION.doc")
'Dim attachFile As New Attachment(lstAttachment.Text)
message.Attachments.Add(attachFile)
emailClient.Send(message)
litStatus.Text = "Message Sent"

Catch ex As Exception
litStatus.Text = ex.ToString()
End Try
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.