By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

Problem with send mail

P: n/a
Hi, I'm not very good in english so excuse me if I have difficulty to
explain my problem.

I want to send a mail with VB.net with this code :

Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
'Votre message
Dim objMessage As New System.Web.Mail.MailMessage
With objMessage
.From = txtFrom.Text
.To = txtTo.Text
'.Cc=
'.Bcc=
.Body = txtBody.Text
.BodyFormat = Web.Mail.MailFormat.Text
.Subject = txtSubject.Text
'.Attachments=
End With
'Quel serveur utiliser?
System.Web.Mail.SmtpMail.SmtpServer = txtServer.Text
'System.Configuration.ConfigurationSettings.AppSet tings("SMTPserver")
pour choisir le smtp par défaut
'Envoi du message
System.Web.Mail.SmtpMail.Send(objMessage)
objMessage = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
But I obtain this error :

An unhandled exception of type 'System.Security.SecurityException' occurred
in system.windows.forms.dll
Additional information: Fail on the request for the permission of type
System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089.

I did a test and use the same code in a ASP application and I can send my
mail. Si I suppose it's some security on my computer but I don't know what
and nobody can help me here. Do you know how
"system.web.mail.smtpmail.send" send the mail. What the right I need to use
this command?
Please help me I really need you!

Thank you
Have a nice day
Sophie


Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sophie,

To make this nice, this is something I made as sample once for a Polish guy,
I hope you find it well that I do not change it in French? (wiadomosch is
message) It is almost the same as yours I thought, however than you can
check it yourself.

\\\
Dim wiadomosc As Web.Mail.MailMessage = New Web.Mail.MailMessage
Dim config As MailAttachment = New
MailAttachment("c:\test1\test.txt")
wiadomosc.Attachments.Add(config)
wiadomosc.From = xxx@xxx
wiadomosc.To = xxx@xxx
wiadomosc.Subject = "..."
wiadomosc.Body = "..."
wiadomosc.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer = "xxxx.xxxx.xx"
System.Web.Mail.SmtpMail.Send(wiadomosc)
///

The smtp server can be any smtp server that you can reach, when you have a
provider mostly even that one, altough he will probably not be lucky with
you when you use this for spam.

I hope this helps?

Cor

"Sophie" <so**********@csp.qc.ca>
Hi, I'm not very good in english so excuse me if I have difficulty to
explain my problem.

I want to send a mail with VB.net with this code :

Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
'Votre message
Dim objMessage As New System.Web.Mail.MailMessage
With objMessage
.From = txtFrom.Text
.To = txtTo.Text
'.Cc=
'.Bcc=
.Body = txtBody.Text
.BodyFormat = Web.Mail.MailFormat.Text
.Subject = txtSubject.Text
'.Attachments=
End With
'Quel serveur utiliser?
System.Web.Mail.SmtpMail.SmtpServer = txtServer.Text
'System.Configuration.ConfigurationSettings.AppSet tings("SMTPserver")
pour choisir le smtp par défaut
'Envoi du message
System.Web.Mail.SmtpMail.Send(objMessage)
objMessage = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
But I obtain this error :

An unhandled exception of type 'System.Security.SecurityException'
occurred
in system.windows.forms.dll
Additional information: Fail on the request for the permission of type
System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089.

I did a test and use the same code in a ASP application and I can send my
mail. Si I suppose it's some security on my computer but I don't know
what
and nobody can help me here. Do you know how
"system.web.mail.smtpmail.send" send the mail. What the right I need to
use
this command?
Please help me I really need you!

Thank you
Have a nice day
Sophie

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.