Sending web email

R

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
 
M

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]
 
R

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
m.posseth said:
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 said:
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
 
M

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

mMsg.Body = msg

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

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

smtpclient.Send(mMsg)

End Sub








Reidar said:
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 said:
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 said:
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
 
H

Herfried K. Wagner [MVP]

Reidar said:
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/>
 

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

Top