How to smtp email?

Discussion in 'ASP .Net' started by =?Utf-8?B?ZW5haw==?=, Jul 2, 2006.

  1. OK, I am getting really frustrated with this. I need to be able to send email
    using smtp. The server that we are using is hosted by a third party. We have
    created a new account with username and password.

    I have searched high and low for a solution to my problem. I have
    implemented what I have found but I still get the same error:

    "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
    (0x80040220): The "SendUsing" configuration value is invalid.

    --- 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.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder
    binder, Object target, Object[] args)

    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj,
    String methodName, Object[] args)

    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 TheColeGroup.Mail.btnSend_Click(Object sender, EventArgs e) in
    D:\Projects\Cole Group\TheColeGroupWeb\Mail.aspx.vb:line 106"



    Here is the code that I am using:

    <code>

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnSend.Click


    Dim objMail As New MailMessage
    lSuccess =

    False

    Try

    If System.IO.File.Exists(Me.txtAttachment.Text) Then
    objMail.To =

    Me.txtTo.Text
    objMail.From = ";" &

    Me.txtFrom.Text
    objMail.Cc =

    Me.txtCC.Text
    objMail.BodyFormat = MailFormat.Text

    objMail.Subject =

    Me.txtSubject.Text
    objMail.Body =

    Me.txtBody.Text
    objMail.Attachments.Add(

    New MailAttachment(Me.txtAttachment.Text, MailEncoding.Base64))
    objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")

    'basic authentication
    objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username")

    'set your username here
    objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password")

    'set your password here
    SmtpMail.SmtpServer.Insert(0, "smtp.mysite.com")

    'SmtpMail.SmtpServer.Insert(0, "smtp_auth.mysite.com")

    SmtpMail.Send(objMail)

    lSuccess =

    True

    End If

    Catch ex As Exception
    sMessage = ex.ToString


    End Try
    End Sub</code>

    Can anyone please HELP ME!?

    Thanks,

    enak

    --
    enak
     
    =?Utf-8?B?ZW5haw==?=, Jul 2, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?ZW5haw==?=

    Mark Rae Guest

    Mark Rae, Jul 2, 2006
    #2
    1. Advertising

  3. Thanks, but I have already seen that. Is there a setting that I need to set
    or do I need to contact the email provider? What is the problem?
    --
    enak


    "Mark Rae" wrote:

    > "enak" <> wrote in message
    > news:...
    >
    > > Can anyone please HELP ME!?

    >
    > http://www.systemwebmail.com
    >
    >
    >
     
    =?Utf-8?B?ZW5haw==?=, Jul 2, 2006
    #3
  4. all you need it to add the HOST and for some hosting companies you need also
    to set the Credentials of an account (user, password) so they can prevent
    spam!

    do that using this:

    Private mailHost As String = "YOUR MAIL HOST"

    Private mailCredentials As New Net.NetworkCredential("YOUR USERNAME", "YOUR
    PASSWORD")

    'create the mail message

    Dim mail As New MailMessage()

    'set the addresses

    mail.From = New MailAddress("YOUR EMAIL", "YOUR NAME")

    mail.To.Add(mailTo)

    'set the content

    mail.Subject = mailSubject

    'screen scrape the html

    Dim html As String = yourHTMLBody

    mail.Body = html

    mail.IsBodyHtml = True

    'send the message

    Dim smtp As New SmtpClient

    smtp.Host = mailHost

    smtp.Credentials = mailCredentials

    Try

    smtp.Send(mail)

    Catch ex As Exception

    Dim ex2 As Exception = ex

    Dim errorMessage As String = String.Empty

    While Not (ex2 Is Nothing)

    errorMessage += ex2.ToString()

    ex2 = ex2.InnerException

    End While

    _error = errorMessage

    End Try


    my _error variable is a private property under a class as string... so
    change it to what you need.

    --

    Bruno Alexandre
    (a Portuguese in KĂžbenhanv, Danmark)


    "enak" <> escreveu na mensagem
    news:...
    > Thanks, but I have already seen that. Is there a setting that I need to
    > set
    > or do I need to contact the email provider? What is the problem?
    > --
    > enak
    >
    >
    > "Mark Rae" wrote:
    >
    >> "enak" <> wrote in message
    >> news:...
    >>
    >> > Can anyone please HELP ME!?

    >>
    >> http://www.systemwebmail.com
    >>
    >>
    >>
     
    Bruno Alexandre, Jul 3, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,090
    Roedy Green
    Jan 24, 2006
  2. Alex Hunsley
    Replies:
    4
    Views:
    3,484
    Tim Williams (gmail)
    Jun 29, 2004
  3. Raaijmakers, Vincent \(GE Infrastructure\)

    RE: sending of mail (smtp) - connection refused - but smtp serveris running!

    Raaijmakers, Vincent \(GE Infrastructure\), Jun 29, 2004, in forum: Python
    Replies:
    0
    Views:
    887
    Raaijmakers, Vincent \(GE Infrastructure\)
    Jun 29, 2004
  4. Copelandia Cyanescens

    smtplib.SMTP "no attributes SMTP"

    Copelandia Cyanescens, Jul 31, 2004, in forum: Python
    Replies:
    2
    Views:
    1,438
    Copelandia Cyanescens
    Jul 31, 2004
  5. ashish makani
    Replies:
    5
    Views:
    606
    Mark Lawrence
    Sep 20, 2012
Loading...

Share This Page