Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Sending Email From Web Parts

  Asked By: Ronald    Date: Mar 25    Category: Sharepoint    Views: 2280

I have a web part that is attempting to send email and I'm using the
regular System.Web.Mail namespace to do this. I am currently getting
the following error message when I attempt to send the mail:

Could not access 'CDO.Message' object. 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 AIU.CustomWebParts.LifeSupport.SendMail() in
vb:line 490 at AIU.CustomWebParts.ServiceProposalWebPart.OnInit
(EventArgs e) in
salWebPart.vb:line 447

I have heard that Sharepoint has its own methods of sending email.
Maybe I should use that instead because it doesn't appear that what I
have is going to work. My code is below.


Dim objMail As New MailMessage

With objMail
.Body = Me.lsEmailBody
.Cc = Me.lsCC
.To = Me.lsTo
.Subject = Me.lsEmailSubject
SmtpMail.SmtpServer = "<ExchangeServer>"

End With



1 Answer Found

Answer #1    Answered By: Cory Brooks     Answered On: Mar 25

I remember I had the similar problem, check the trust level in web.config file. Create a custom trust level, you can also set it Full ( not recommended). Your code below will work 100%.

Didn't find what you were looking for? Find more on Sending Email From Web Parts Or get search suggestion and latest updates.