HOW TO: Send email using System.Net.Mail

Rate It (28)

Last post 08-01-2007 8:01 AM by Johnny be good. 173 replies.

Sort Posts:

  • Re: HOW TO: Send email using System.Net.Mail

    11-15-2006, 1:49 AM
    Locked
    • Member
      5 point Member
    • samirvohra
    • Member since 11-15-2006, 6:32 AM
    • Posts 1
    any one can send good code for sending mail to group of pople..
  • Re: HOW TO: Send email using System.Net.Mail

    11-15-2006, 10:08 AM
    Locked
    • All-Star
      30,698 point All-Star
    • StrongTypes
    • Member since 12-13-2005, 4:21 PM
    • California
    • Posts 6,007
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    samirvohra:
    any one can send good code for sending mail to group of pople..

    That is a good observation.

  • Re: HOW TO: Send email using System.Net.Mail

    12-12-2006, 7:31 AM
    Locked
    • Member
      15 point Member
    • prashar18
    • Member since 12-11-2006, 5:07 PM
    • London
    • Posts 3
    Is there any way to set the bounce address i.e. the bounced emails should be sent to different email than the one in the from email. I have tried replyto, return-path, reverse-path but nothing is working........
  • Re: HOW TO: Send email using System.Net.Mail

    12-12-2006, 9:41 AM
    Locked
    • All-Star
      30,698 point All-Star
    • StrongTypes
    • Member since 12-13-2005, 4:21 PM
    • California
    • Posts 6,007
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    prashar18:
    Is there any way to set the bounce address i.e. the bounced emails should be sent to different email than the one in the from email. I have tried replyto, return-path, reverse-path but nothing is working........

    If you read some of the earlier threads in this post, this topic has already been discussed.

  • Re: HOW TO: Send email using System.Net.Mail

    12-20-2006, 8:58 AM
    Locked
    • Member
      12 point Member
    • xboddy
    • Member since 11-02-2005, 10:50 AM
    • Sydney,Australia
    • Posts 6
    Hi

    My application was working until I downloaded a couple of Windows patches and IE7 on "localhost". I'm using my IPS's SMTP and get no error at all. I don't think the new updates for .net can cause any difficulties, can they? Any thoughts? Thanks

     

  • Re: HOW TO: Send email using System.Net.Mail

    12-20-2006, 9:11 AM
    Locked
    • Member
      12 point Member
    • xboddy
    • Member since 11-02-2005, 10:50 AM
    • Sydney,Australia
    • Posts 6
    xboddy:
    Hi

    I'm using my IPS's SMTP and

     

     well, I mean ISP.

     

  • Re: HOW TO: Send email using System.Net.Mail

    12-30-2006, 5:47 PM
    Locked
    • Member
      33 point Member
    • rippleman
    • Member since 12-18-2006, 3:21 AM
    • Posts 91

    Hello, I have created a public shared function that I can access through several different pages.

     However, I am getting  a message that states:  Function 'SendEmail' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

    so, the question is, how do I get rid of this error?

    This is how the first part of the function looks:

     
    Public Class EmailUtils

    Public Shared Function SendEmail(ByVal toemail As String, ByVal fromname As String, ByVal fromemail As String, ByVal subject As String, ByVal message As String, ByVal attachment As String)

     
    Thanks in advance.
     


     

  • Re: HOW TO: Send email using System.Net.Mail

    12-31-2006, 12:04 AM
    Locked
    • Member
      12 point Member
    • xboddy
    • Member since 11-02-2005, 10:50 AM
    • Sydney,Australia
    • Posts 6

    Hi

    Firstly you haven't defined the type of function. (i.e. As String etc.). Secondly if you don't want your function to return a value then use Sub instead.

     

  • Re: HOW TO: Send email using System.Net.Mail

    01-01-2007, 10:38 AM
    Locked
    • Member
      33 point Member
    • rippleman
    • Member since 12-18-2006, 3:21 AM
    • Posts 91
    xboddy:

    Hi

    Firstly you haven't defined the type of function. (i.e. As String etc.). Secondly if you don't want your function to return a value then use Sub instead.

     

     Oh gosh, thanks.  I think I was trying to get this to work prior to my cup of coffee.  Big Smile
     

  • Re: HOW TO: Send email using System.Net.Mail

    01-04-2007, 9:59 AM
    Locked
    • Member
      9 point Member
    • Bernhard
    • Member since 06-08-2006, 2:27 PM
    • Austria
    • Posts 4

    Hello,

    I also have got the problem, that the return path doesn't work, even  when I use the DeliveryNotificationOptions. Whats wrong? The failure message is allways sent to myAdr1@gmx.net and not to myReturnPath@domain.com. Please help!!!

    MailMessage msg = new MailMessage("myAdr1@gmx.net", "asdf@asfRsdfs.net", "testmail", "Testmail");
    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    msg.Headers.Add("Return-Path", "myReturnPath@domain.com");
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "myHost";
    smtp.Send(msg);
    
    

       

  • Re: HOW TO: Send email using System.Net.Mail

    01-14-2007, 10:54 PM
    Locked
    • Member
      77 point Member
    • raylinder
    • Member since 06-25-2005, 7:28 AM
    • Cornfields, AZ
    • Posts 23
    Bernhard:

    Hello,

    I also have got the problem, that the return path doesn't work, even  when I use the DeliveryNotificationOptions. Whats wrong? The failure message is allways sent to myAdr1@gmx.net and not to myReturnPath@domain.com. Please help!!!

    MailMessage msg = new MailMessage("myAdr1@gmx.net", "asdf@asfRsdfs.net", "testmail", "Testmail");
    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    msg.Headers.Add("Return-Path", "myReturnPath@domain.com");
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "myHost";
    smtp.Send(msg);
    
    

       




    Um, you could try using:

    msg.ReplyTo = new Message("myReturnPath@domain.com");

    instead of:

    msg.Headers.Add("Return-Path", myReturnPath@domain.com);

    or:

    msg.Headers.Add("Reply-To", myReturnPath@domain.com);

    In fact, don't even use "Headers.Add"...

    Question: Do people ever go to MSDN and actually read anything there?

    Ray Linder
    Glacsy | Glacsy.com
    raylinder@glacsy.com
  • Re: HOW TO: Send email using System.Net.Mail

    01-15-2007, 1:22 AM
    Locked
    • Member
      9 point Member
    • Bernhard
    • Member since 06-08-2006, 2:27 PM
    • Austria
    • Posts 4

    Yes I do read at the msdn; And also RFC's if required, that's the reason why I add the retrun-path header, because there is a difference between return-path and reply-to. It's also a difference between the return-path and the sender property at the mail.

    And the required functionality would be to set the return-path.

    But it doesn't matter because the sourcecode isn't wrong! It is a problem at the SMTP Server of the IIS I'm using and also a problem at the microsoft exchange server.
    I did a MS Support Call because of this issue and as a result I got the information, that they changed the implementations at the SMTP about two years ago, so that this isn't rfc compliant anymore and it's coded, that the delivery notifications will be sent to the sender (because of email spoofing)

    regards

    Bernhard
    http://www.raupes.net

  • Re: HOW TO: Send email using System.Net.Mail

    01-16-2007, 1:11 PM
    Locked
    • Participant
      1,177 point Participant
    • gsdtech
    • Member since 12-21-2006, 9:36 PM
    • Kennewick, WA
    • Posts 185

    I've just enabled mailing to multiple recipients using Ryan's suggestion of a param array. Here's how to quickly modify your code to make this work in VB.NET.

    1. Modify the Code File - mailHelper.vb

    Update the first few lines of the SendMailMessage subroutine as follows. Make the ParamArray the final parameter passed. Then loop through the ParamArray, adding each string (email address) as a recipient.

    ==================================

    Public Shared Sub SendMailMessage(ByVal from As String, ByVal bcc As String, ByVal cc As String, _
        ByVal subject As String, ByVal body As String, ByVal ParamArray strTo() As String)
        ' Instantiate a new instance of MailMessage
        Dim mMailMessage As New MailMessage()
    
        ' Set the sender address of the mail message
         mMailMessage.From = New MailAddress(from)
        ' Set the recepient addresses of the mail message
         For Each s As String In strTo
            mMailMessage.To.Add(New MailAddress(s))
         Next
    ==================================

    2. Pass Multiple Addresses into the ParamArray

    Anywhere you call the MailHelper, you can pass in multiple recipients as follows.

    ==================================

    ' Prepare the email
    Dim strTo() As String = {"Recipient1@email.xyz", "Recipient2@email.xyz"}
    Dim strFrom, strBcc, strCC, strSubject, strBody As String
    strFrom = "me@email.xyz"
    strBcc = "bccgal@email.xyz"
    strCC = "ccguy@email.xyz"
    strSubject = "This is the message subject."
    strBody = "This ticket the message body."
    
    ' Send the email
    MailHelper.SendMailMessage(strFrom, strBcc, strCC, strSubject, strBody, strTo)
    ==================================
    Ryan, your post was extremely helpful. Thanks a lot!
    "Peace is Every Step." -Thich Nhat Hanh
  • Re: HOW TO: Send email using System.Net.Mail

    01-17-2007, 2:32 AM
    Locked
    • Star
      8,018 point Star
    • aus_nexxus
    • Member since 11-01-2002, 11:14 PM
    • Australia
    • Posts 1,156
    • TrustedFriends-MVPs

    Check out what we did on the DotNetNuke project for handling bulk email.  Wwe have some good code on threading and sending lots of mail.

    Cheers

    Philip Beadle (MVP, MCAD, MCT DotNetNuke Core Team)
  • Re: HOW TO: Send email using System.Net.Mail

    01-21-2007, 3:29 PM
    Locked
    • Member
      21 point Member
    • mabho
    • Member since 06-29-2006, 2:43 PM
    • Rio de Janeiro
    • Posts 11
    Hi. would like to know if I can set a friendly name for the e-mail from attribute, so that users will see that friendly name in their incoming box instead of the raw e-mail address. I wonder if that can be set in the web.config file in the <smtp> line or if my only choice is to set it up in the MailMessage object. Thanks a lot.
Page 9 of 12 (174 items) « First ... < Previous 7 8 9 10 11 Next > ... Last »