Sending web email

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reidar

    #1

    Sending web email

    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.Mail Message 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.posseth

    #2
    Re: Sending web email

    i use this in all my projects
    Imports System.Net.Mail

    Private Function fsmtpClient() As SmtpClient

    fsmtpClient = New
    SmtpClient(Conf igurationManage r.AppSettings(" smtpHost").ToSt ring,
    Integer.Parse(C onfigurationMan ager.AppSetting s("smtpPort") ))

    fsmtpClient.Use DefaultCredenti als = 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(Con figurationManag er.AppSettings( "errMailFro m"))

    mMsg.Priority = MailPriority.Hi gh

    mMsg.Body = msg

    Dim errto() As String =
    ConfigurationMa nager.AppSettin gs("errMailTo") .Split(CChar("; "))

    For Each adress As String In errto

    mMsg.To.Add(New MailAddress(adr ess))

    Next

    fsmtpClient.Sen d(mMsg)

    End Sub





    this works perfect :-)



    regards



    Michel posseth [MCP]





    "Reidar" <reidar@eivon.n o> wrote in message
    news:OG7oxD2RGH A.256@TK2MSFTNG P14.phx.gbl...[color=blue]
    >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.[/color]


    [color=blue]
    > When I run the code I get warnings saying that System.Web.Mail Message 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
    >
    >[/color]


    Comment

    • Reidar

      #3
      Re: Sending web email

      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" <michelp@nohaus ystems.nl> skrev i melding
      news:uptzrs2RGH A.4456@TK2MSFTN GP14.phx.gbl...[color=blue]
      >i use this in all my projects
      > Imports System.Net.Mail
      >
      > Private Function fsmtpClient() As SmtpClient
      >
      > fsmtpClient = New
      > SmtpClient(Conf igurationManage r.AppSettings(" smtpHost").ToSt ring,
      > Integer.Parse(C onfigurationMan ager.AppSetting s("smtpPort") ))
      >
      > fsmtpClient.Use DefaultCredenti als = 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(Con figurationManag er.AppSettings( "errMailFro m"))
      >
      > mMsg.Priority = MailPriority.Hi gh
      >
      > mMsg.Body = msg
      >
      > Dim errto() As String =
      > ConfigurationMa nager.AppSettin gs("errMailTo") .Split(CChar("; "))
      >
      > For Each adress As String In errto
      >
      > mMsg.To.Add(New MailAddress(adr ess))
      >
      > Next
      >
      > fsmtpClient.Sen d(mMsg)
      >
      > End Sub
      >
      >
      >
      >
      >
      > this works perfect :-)
      >
      >
      >
      > regards
      >
      >
      >
      > Michel posseth [MCP]
      >
      >
      >
      >
      >
      > "Reidar" <reidar@eivon.n o> wrote in message
      > news:OG7oxD2RGH A.256@TK2MSFTNG P14.phx.gbl...[color=green]
      >>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.[/color]
      >
      >
      >[color=green]
      >> When I run the code I get warnings saying that System.Web.Mail Message 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
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • m.posseth

        #4
        Re: Sending web email

        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("No reply@youradres s.com")

        mMsg.Body = msg

        mMsg.To.Add(New MailAddress(Mai lto))

        Dim smtpclient As New SmtpClient("You rHost(NameOrIp) ", 25)

        smtpclient.Send (mMsg)

        End Sub








        "Reidar" <reidar@eivon.n o> wrote in message
        news:Ov9C752RGH A.4608@tk2msftn gp13.phx.gbl...[color=blue]
        > 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" <michelp@nohaus ystems.nl> skrev i melding
        > news:uptzrs2RGH A.4456@TK2MSFTN GP14.phx.gbl...[color=green]
        >>i use this in all my projects
        >> Imports System.Net.Mail
        >>
        >> Private Function fsmtpClient() As SmtpClient
        >>
        >> fsmtpClient = New
        >> SmtpClient(Conf igurationManage r.AppSettings(" smtpHost").ToSt ring,
        >> Integer.Parse(C onfigurationMan ager.AppSetting s("smtpPort") ))
        >>
        >> fsmtpClient.Use DefaultCredenti als = 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(Con figurationManag er.AppSettings( "errMailFro m"))
        >>
        >> mMsg.Priority = MailPriority.Hi gh
        >>
        >> mMsg.Body = msg
        >>
        >> Dim errto() As String =
        >> ConfigurationMa nager.AppSettin gs("errMailTo") .Split(CChar("; "))
        >>
        >> For Each adress As String In errto
        >>
        >> mMsg.To.Add(New MailAddress(adr ess))
        >>
        >> Next
        >>
        >> fsmtpClient.Sen d(mMsg)
        >>
        >> End Sub
        >>
        >>
        >>
        >>
        >>
        >> this works perfect :-)
        >>
        >>
        >>
        >> regards
        >>
        >>
        >>
        >> Michel posseth [MCP]
        >>
        >>
        >>
        >>
        >>
        >> "Reidar" <reidar@eivon.n o> wrote in message
        >> news:OG7oxD2RGH A.256@TK2MSFTNG P14.phx.gbl...[color=darkred]
        >>>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.[/color]
        >>
        >>
        >>[color=darkred]
        >>> When I run the code I get warnings saying that System.Web.Mail Message 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
        >>>
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Sending web email

          "Reidar" <reidar@eivon.n o> schrieb:[color=blue]
          >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.Mail Message 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[/color]

          'System.Net.Mai l' 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.systemnetma il.net/>

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

          Comment

          Working...