Solved

.NET EMAIL CDO.MESSAGE

Posted on 2004-03-30
5
1,217 Views
Last Modified: 2007-12-19
I have a network here at work. I am going to have my computer as the main Server. I have another computer that will be used to sending mail. Do i need to setup the SMTP server ? If so where on my computer or the Mail Server ? Im a newbie at this so pls HELP! Here is the code:

'Set the smtp server
SmtpMail.SmtpServer = "greg"

'Send the email
SmtpMail.Send(objMail)

ERROR MESSAGE:
An error occured while processing the email. Please review the following. Error sending email Could not access 'CDO.Message' object. Error String System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server. --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) --- End of inner exception stack trace --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at ClinicLogin.sendEmail.btnSend_Click(Object sender, EventArgs e) in C:\WEB_ROOT\WebForms\ClinicLogin\sendEmail.aspx.vb:line 164
0
Comment
Question by:jainpriyanka
5 Comments
 
LVL 9

Expert Comment

by:msdixon
ID: 10719082
you need to set up the box "greg" as an smtp server. you will also need to set it up as a mail relay. when you do this, you will only want to relay from specific machines, if possible. otherwise, if this is an externally availalbe server, your server will be a spam relay.
0
 
LVL 1

Expert Comment

by:dummie_q
ID: 10719573
Sorry..I don't quite get the idea. Its fine to have one more machine for sending the mails. That, I guess can be used as an exchange server or something like that. But for sending mail from your program, you can as well configure SMTP on your machine itself. Then, when you use the SMTP object and send a mail, if you are hooked on to the n/w, it will be configured to send the mail through the other machine set up for sending emails.

Diff parts of the code here..
using System.Web.mail;

...

MailMessage message = new MailMessage();
message.From = "name@urdomain.com";
message.to = "toname@domain.com"
message.subject = "";
message.body = "";
:
:

SMTPMail.Send(message);

Note: Leave out the SMTPMail.SMTPServer = "greg" part. By default, it is initialized to ur localhost.



0
 
LVL 9

Expert Comment

by:malharone
ID: 10719685
this should help
i'm attaching a code for vb.net for a form that lets you send emails

-------------------------------------------------------------------

Option Explicit On

Imports System.Web.Mail

Public Class frmEmail
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtTo As System.Windows.Forms.TextBox
    Friend WithEvents txtFrom As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtSubject As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents cmdCancel As System.Windows.Forms.Button
    Friend WithEvents cmdEmailLog As System.Windows.Forms.Button
    Friend WithEvents txtContent As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmEmail))
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.cmdCancel = New System.Windows.Forms.Button()
        Me.cmdEmailLog = New System.Windows.Forms.Button()
        Me.txtTo = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.txtFrom = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtSubject = New System.Windows.Forms.TextBox()
        Me.txtContent = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdCancel, Me.cmdEmailLog, Me.txtTo, Me.Label1, Me.txtFrom, Me.Label2, Me.Label3, Me.txtSubject, Me.txtContent, Me.Label4})
        Me.Panel1.Location = New System.Drawing.Point(8, 32)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(800, 376)
        Me.Panel1.TabIndex = 32
        '
        'cmdCancel
        '
        Me.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdCancel.Location = New System.Drawing.Point(448, 336)
        Me.cmdCancel.Name = "cmdCancel"
        Me.cmdCancel.Size = New System.Drawing.Size(160, 32)
        Me.cmdCancel.TabIndex = 32
        Me.cmdCancel.Text = "     &Cancel"
        '
        'cmdEmailLog
        '
        Me.cmdEmailLog.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.cmdEmailLog.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdEmailLog.Location = New System.Drawing.Point(280, 336)
        Me.cmdEmailLog.Name = "cmdEmailLog"
        Me.cmdEmailLog.Size = New System.Drawing.Size(160, 32)
        Me.cmdEmailLog.TabIndex = 31
        Me.cmdEmailLog.Text = "    &Send Email"
        '
        'txtTo
        '
        Me.txtTo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtTo.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTo.Location = New System.Drawing.Point(112, 8)
        Me.txtTo.Name = "txtTo"
        Me.txtTo.Size = New System.Drawing.Size(672, 20)
        Me.txtTo.TabIndex = 1
        Me.txtTo.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "To"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtFrom
        '
        Me.txtFrom.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtFrom.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtFrom.Location = New System.Drawing.Point(112, 32)
        Me.txtFrom.Name = "txtFrom"
        Me.txtFrom.Size = New System.Drawing.Size(672, 20)
        Me.txtFrom.TabIndex = 1
        Me.txtFrom.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 32)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "Your Email Addr."
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 56)
        Me.Label3.Name = "Label3"
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "Subject"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtSubject
        '
        Me.txtSubject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtSubject.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtSubject.Location = New System.Drawing.Point(112, 56)
        Me.txtSubject.Name = "txtSubject"
        Me.txtSubject.Size = New System.Drawing.Size(672, 20)
        Me.txtSubject.TabIndex = 1
        Me.txtSubject.Text = ""
        '
        'txtContent
        '
        Me.txtContent.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtContent.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtContent.Location = New System.Drawing.Point(112, 80)
        Me.txtContent.Multiline = True
        Me.txtContent.Name = "txtContent"
        Me.txtContent.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtContent.Size = New System.Drawing.Size(672, 248)
        Me.txtContent.TabIndex = 1
        Me.txtContent.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 80)
        Me.Label4.Name = "Label4"
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "Content"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'frmEmail
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(816, 416)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1})
        Me.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmEmail"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Send Email"
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region " PRIVATE PROPERTIES "

#End Region

#Region " PUBLIC PROPERTIES "

#End Region

#Region " MISC DECLARATIONS "

#End Region

#Region " PRIVATE FUNCTIONS "

#End Region

#Region " PUBLIC FUNCTIONS "

#End Region

#Region " CONTROL/FORM EVENTS "

#End Region

#Region " CHILD-CONTROL EVENTS "
    Private Sub cmdEmailLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEmailLog.Click
        If Me.txtTo.Text Is Nothing OrElse Me.txtTo.Text.Trim.Length < 1 OrElse _
            Me.txtFrom.Text Is Nothing OrElse Me.txtFrom.Text.Trim.Length < 1 OrElse _
            Me.txtSubject.Text Is Nothing OrElse Me.txtSubject.Text.Trim.Length < 1 OrElse _
            Me.txtContent.Text Is Nothing OrElse Me.txtContent.Text.Trim.Length < 1 Then

            MessageBox.Show("The email can not be sent since one or more is incomplete / blank:" & vbCrLf & " - To" & vbCrLf & " - From" & vbCrLf & " - Subject " & vbCrLf & " - Content", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            Dim eml As New System.Web.Mail.MailMessage()
            With eml
                .To = Me.txtTo.Text
                .Bcc = Me.txtFrom.Text
                .From = Me.txtFrom.Text
                .Subject = Me.txtSubject.Text
                .Body = Me.txtContent.Text
                .Priority = MailPriority.High
                .BodyFormat = MailFormat.Text
            End With
            If MessageBox.Show("Send email?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
                Try
                    System.Web.Mail.SmtpMail.Send(eml)
                    MessageBox.Show("The email has been successfully sent.", "Email", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Me.Close()
                Catch ex As Exception
                    MessageBox.Show("The following error occured while sending email:" & vbCrLf & ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
            End If
        End If
    End Sub
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        '''If MessageBox.Show("Are you sure you want to close this form and discard all/any changes?", "Confirm Cancel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
        Me.Close()
        '''End If
    End Sub
#End Region

End Class
0
 

Author Comment

by:jainpriyanka
ID: 10724239
"Greg" is the computer on the network that has the email server running. I would prefer if i can just change settings on my computer and not on the Email Server. Please tell me how SMTP is to be configured from IIS on my computer and if I have to configure the Email server what will the steps be?
Thnx
0
 
LVL 1

Accepted Solution

by:
dummie_q earned 125 total points
ID: 10728204
Hi priyanka..
Usually when the IIS is installed on ur machine, the SMTp is also automatically configured.
Go to Start->Run
Type inetmgr
This will take to u to InetMgr Adm menu
Check to see if there is something like "Default SMTP virtual server"
Right click and go to "Properties"

In the General TAB make sure IP Addresses are set to "ALL Unassigned" ..guess this is deault.

Next go to Security tab: Here, ensure that permission is set for yourlogin..say "jainpriyanka"
Usually, by default, Administrators will have privilage. Alternatively, I guess, if you set the privilage for ur account as "Administrator" , it should work.

Thats all u need to do. Make sure you are in the same network as that of computer "GREG"
For example, if u r in the domain say, "TESTDOMAIN", then in ur inetmgr domain, if ur comp name is "jain", u will see "jain.TESTDOMAIN".
Similarly for "GREG", it will be "GREG.TESTDOMAIN".

This will ensure that all ur mails are routed thru GREG. Even otherwise, once u r on a n/w, ur SMTP can still manage to send ur email

hth..
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now