How to smtp email?

G

Guest

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 = "(e-mail address removed);" &

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
 
G

Guest

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?
 
B

Bruno Alexandre

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top