473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with send mail

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
1 1774
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bruce W...1 | last post by:
In my effort to learn PHP I'm playing with some simple email scripts. They worked a few days ago but they stopped working. The only thing I've done to this Windows 2000 PC in this time was a...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
4
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
5
by: ElanKathir | last post by:
Hi ! I wrote one code for Send the E-mail, But that code have some problem , So please help me Here i paste my code and Error: Error: Server Error in '/Elan_Sample' Application. ...
4
by: k.visube | last post by:
In my ASP application,i need to send a formatted text mail (i.e with newline characters). here in my application i used a function in javascript which construts the mail body sample snippet ...
3
by: Pav | last post by:
Hi, I am developing a small Intranet web application which needs to send mails to our coporate Ids. I am using CDONTS, But my mails never leave Que folder. Not able to find out what the...
2
by: joseph2000 | last post by:
Hi, I have problem with e-mails which are being send via System.Web.Mail.SmtpMail class but before describing the problem itself first I'd like to show shortly what I'm doing on the server. ...
1
by: the_ricka | last post by:
Hi all, I'm fairly new to python, but very excited about it's potential. I'm trying to write a simple program that will accept input from a command line and send email. The parameters I used on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.