Home All Groups Group Topic Archive Search About
Author
14 Mar 2006 12:15 PM
Reidar
I am trying to send web email in vs2005, but haven't succeeded so far.
I found an example in C# to make a Console application.
The top of the code is
using System;
using System.Web.Mail;
I have added a reference System.Web.
When I run the code I get warnings saying that System.Web.MailMessage is
'obsolete'.
Alternative is System.Net.Mail.MailMessage
When I change the System.Web.Mail to System.Net.Mail, I can't find any
reference for System.Net.Mail
Does anybody have a good example to follow just to send a plain web email
whith From, To, Message, Body and Attachment.
Preferrably in Vb.

regards
reidarT

Author
14 Mar 2006 1:28 PM
m.posseth
i use this in all my projects
Imports System.Net.Mail

Private  Function fsmtpClient() As SmtpClient

fsmtpClient = New
SmtpClient(ConfigurationManager.AppSettings("smtpHost").ToString,
Integer.Parse(ConfigurationManager.AppSettings("smtpPort")))

fsmtpClient.UseDefaultCredentials = True

End Function



Public Shared Sub adminErrorMail(ByVal msg As String, Optional ByVal
Notification As Boolean = False)

Dim mMsg As New MailMessage

If Notification Then

mMsg.Subject = "H-base.com Notification : " & Now.ToString

Else

mMsg.Subject = "H-base.com Application error occured : " & Now.ToString

End If

mMsg.From = New MailAddress(ConfigurationManager.AppSettings("errMailFrom"))

mMsg.Priority = MailPriority.High

mMsg.Body = msg

Dim errto() As String =
ConfigurationManager.AppSettings("errMailTo").Split(CChar(";"))

For Each adress As String In errto

mMsg.To.Add(New MailAddress(adress))

Next

fsmtpClient.Send(mMsg)

End Sub





this works perfect :-)



regards



Michel posseth [MCP]





Show quoteHide quote
"Reidar" <rei***@eivon.no> wrote in message
news:OG7oxD2RGHA.256@TK2MSFTNGP14.phx.gbl...
>I am trying to send web email in vs2005, but haven't succeeded so far.
> I found an example in C# to make a Console application.
> The top of the code is
> using System;
> using System.Web.Mail;
> I have added a reference System.Web.



> When I run the code I get warnings saying that System.Web.MailMessage is
> 'obsolete'.
> Alternative is System.Net.Mail.MailMessage
> When I change the System.Web.Mail to System.Net.Mail, I can't find any
> reference for System.Net.Mail
> Does anybody have a good example to follow just to send a plain web email
> whith From, To, Message, Body and Attachment.
> Preferrably in Vb.
>
> regards
> reidarT
>
>
Author
14 Mar 2006 1:51 PM
Reidar
Could you help me a bit more.
Are you placing this code in a webform with txtfields To, CC, Message,
Body...
or what?
reidar
Show quoteHide quote
"m.posseth" <mich***@nohausystems.nl> skrev i melding
news:uptzrs2RGHA.4456@TK2MSFTNGP14.phx.gbl...
>i use this in all my projects
> Imports System.Net.Mail
>
> Private  Function fsmtpClient() As SmtpClient
>
> fsmtpClient = New
> SmtpClient(ConfigurationManager.AppSettings("smtpHost").ToString,
> Integer.Parse(ConfigurationManager.AppSettings("smtpPort")))
>
> fsmtpClient.UseDefaultCredentials = True
>
> End Function
>
>
>
> Public Shared Sub adminErrorMail(ByVal msg As String, Optional ByVal
> Notification As Boolean = False)
>
> Dim mMsg As New MailMessage
>
> If Notification Then
>
> mMsg.Subject = "H-base.com Notification : " & Now.ToString
>
> Else
>
> mMsg.Subject = "H-base.com Application error occured : " & Now.ToString
>
> End If
>
> mMsg.From = New
> MailAddress(ConfigurationManager.AppSettings("errMailFrom"))
>
> mMsg.Priority = MailPriority.High
>
> mMsg.Body = msg
>
> Dim errto() As String =
> ConfigurationManager.AppSettings("errMailTo").Split(CChar(";"))
>
> For Each adress As String In errto
>
> mMsg.To.Add(New MailAddress(adress))
>
> Next
>
> fsmtpClient.Send(mMsg)
>
> End Sub
>
>
>
>
>
> this works perfect :-)
>
>
>
> regards
>
>
>
> Michel posseth [MCP]
>
>
>
>
>
> "Reidar" <rei***@eivon.no> wrote in message
> news:OG7oxD2RGHA.256@TK2MSFTNGP14.phx.gbl...
>>I am trying to send web email in vs2005, but haven't succeeded so far.
>> I found an example in C# to make a Console application.
>> The top of the code is
>> using System;
>> using System.Web.Mail;
>> I have added a reference System.Web.
>
>
>
>> When I run the code I get warnings saying that System.Web.MailMessage is
>> 'obsolete'.
>> Alternative is System.Net.Mail.MailMessage
>> When I change the System.Web.Mail to System.Net.Mail, I can't find any
>> reference for System.Net.Mail
>> Does anybody have a good example to follow just to send a plain web email
>> whith From, To, Message, Body and Attachment.
>> Preferrably in Vb.
>>
>> regards
>> reidarT
>>
>>
>
>
Author
14 Mar 2006 2:48 PM
m.posseth
Well i have placed the code in a public class so all my pages can use it
( it was a actuall copy paste of functioning code in one of my projects )

here is a simplified version in one method

Public Shared Sub SendMail(ByVal msg As String, ByVal Mailto As String)

Dim mMsg As New MailMessage

mMsg.Subject = "Your Subject"

mMsg.From = New MailAddress("Nore***@youradress.com")

mMsg.Body = msg

mMsg.To.Add(New MailAddress(Mailto))

Dim smtpclient As New SmtpClient("YourHost(NameOrIp)", 25)

smtpclient.Send(mMsg)

End Sub








Show quoteHide quote
"Reidar" <rei***@eivon.no> wrote in message
news:Ov9C752RGHA.4608@tk2msftngp13.phx.gbl...
> Could you help me a bit more.
> Are you placing this code in a webform with txtfields To, CC, Message,
> Body...
> or what?
> reidar
> "m.posseth" <mich***@nohausystems.nl> skrev i melding
> news:uptzrs2RGHA.4456@TK2MSFTNGP14.phx.gbl...
>>i use this in all my projects
>> Imports System.Net.Mail
>>
>> Private  Function fsmtpClient() As SmtpClient
>>
>> fsmtpClient = New
>> SmtpClient(ConfigurationManager.AppSettings("smtpHost").ToString,
>> Integer.Parse(ConfigurationManager.AppSettings("smtpPort")))
>>
>> fsmtpClient.UseDefaultCredentials = True
>>
>> End Function
>>
>>
>>
>> Public Shared Sub adminErrorMail(ByVal msg As String, Optional ByVal
>> Notification As Boolean = False)
>>
>> Dim mMsg As New MailMessage
>>
>> If Notification Then
>>
>> mMsg.Subject = "H-base.com Notification : " & Now.ToString
>>
>> Else
>>
>> mMsg.Subject = "H-base.com Application error occured : " & Now.ToString
>>
>> End If
>>
>> mMsg.From = New
>> MailAddress(ConfigurationManager.AppSettings("errMailFrom"))
>>
>> mMsg.Priority = MailPriority.High
>>
>> mMsg.Body = msg
>>
>> Dim errto() As String =
>> ConfigurationManager.AppSettings("errMailTo").Split(CChar(";"))
>>
>> For Each adress As String In errto
>>
>> mMsg.To.Add(New MailAddress(adress))
>>
>> Next
>>
>> fsmtpClient.Send(mMsg)
>>
>> End Sub
>>
>>
>>
>>
>>
>> this works perfect :-)
>>
>>
>>
>> regards
>>
>>
>>
>> Michel posseth [MCP]
>>
>>
>>
>>
>>
>> "Reidar" <rei***@eivon.no> wrote in message
>> news:OG7oxD2RGHA.256@TK2MSFTNGP14.phx.gbl...
>>>I am trying to send web email in vs2005, but haven't succeeded so far.
>>> I found an example in C# to make a Console application.
>>> The top of the code is
>>> using System;
>>> using System.Web.Mail;
>>> I have added a reference System.Web.
>>
>>
>>
>>> When I run the code I get warnings saying that System.Web.MailMessage is
>>> 'obsolete'.
>>> Alternative is System.Net.Mail.MailMessage
>>> When I change the System.Web.Mail to System.Net.Mail, I can't find any
>>> reference for System.Net.Mail
>>> Does anybody have a good example to follow just to send a plain web
>>> email whith From, To, Message, Body and Attachment.
>>> Preferrably in Vb.
>>>
>>> regards
>>> reidarT
>>>
>>>
>>
>>
>
>
Author
14 Mar 2006 6:23 PM
Herfried K. Wagner [MVP]
"Reidar" <rei***@eivon.no> schrieb:
>I am trying to send web email in vs2005, but haven't succeeded so far.
> I found an example in C# to make a Console application.
> The top of the code is
> using System;
> using System.Web.Mail;
> I have added a reference System.Web.
> When I run the code I get warnings saying that System.Web.MailMessage is
> 'obsolete'.
> Alternative is System.Net.Mail.MailMessage
> When I change the System.Web.Mail to System.Net.Mail, I can't find any
> reference for System.Net.Mail

'System.Net.Mail' is implemented in "system.dll", not "System.Web.dll".

Additional information:

<URL:http://msdn2.microsoft.com/en-us/library/system.net.mail.mailmessage(VS.80).aspx>

<URL:http://www.systemnetmail.net/>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>