Sending Email using System.Net.Mail

Posted on 2008-11-07
Last Modified: 2013-11-30
I have some code that sends an activation code to a user when they sign up for a service.  Some people are not getting the email at all, even when they check their spam/bulk folder.  After reviewing the mail server logs, ALL the emails were successfully sent via the SMTP service but some are just not being delivered.

Could the email provider be flagging this email  as spam?  Is there anything I can do to prevent this?
Dim strMailSubject As String

        Dim strMailBody As String

        strMailSubject = "Welcome"

        Dim ToAddress As String = txtEmail.Text.Trim

        Dim mm As New MailMessage("", ToAddress)

        'Dim mm As New MailMessage(ToAddress, ToAddress)


            mm.Subject = strMailSubject

            strMailBody = "Dear " & Trim(lblFName.Text) & ","

            strMailBody = strMailBody & "<BR><BR>Thank you for registering. To complete your registration, please follow the link below or just enter <b>" & lblActivationCode.Text & " </b>in the activate account form"

            strMailBody = strMailBody & "<br><br>" & "<a href='http://" & Request.Url.Host & Request.ApplicationPath & "/Verify.aspx?UserID=" & sUserID & "&ActivationCode=" & lblActivationCode.Text & " '>" & "http://" & Request.Url.Host & Request.ApplicationPath & "/Verify.aspx?UserID=" & sUserID & "&ActivationCode=" & lblActivationCode.Text & "</a>"


            mm.Body = strMailBody

            mm.IsBodyHtml = True

            Dim smtp As New SmtpClient


            lblError.Visible = False

            pnlSucess.visible = True

        Catch ex As Exception

            Me.pnlError.Visible = True

            lblError.Visible = True

            lblError.Text = "<li>" & ex.ToString & "</li>"

            lblError.Text = lblError.Text & "<li>We are currently having trouble processing your email. Please check that your email address is correct. If problem persists, please try again at a later time.</li>"

        End Try

Open in new window

Question by:Paulconsulting
    LVL 2

    Expert Comment

    If the email is successfully sent out by your SMTP server then the problem is not on your side.  The recipient server may be flagging it as spam.  You will have to contact the Admin on the recipient side to track down why the email was not delivered.  If this problem happens often you may want to check your DNS settings and verify your domain/smtp server is not on any black lists.

    try these sites:
    LVL 22

    Expert Comment

    >>>Could the email provider be flagging this email  as spam?
    Very likely.
    >>>Is there anything I can do to prevent this?
    Yes, but not much.
    "Welcome" is not a very good subject and might be caught as a spam. Try something like "Activation code for your registration". Bottom line: be more specific and more informative, so it will have more chances to pass the spam filter.

    Author Comment

    Thanks, I ran the mail server IP and domain name with those tools you suggested and everything checked out ok, any other suggestions? My co-worker suggested researching email headers.

    Author Comment

    Thanks for the suggestion prairiedog, I will give that a try.
    LVL 22

    Accepted Solution

    Two other things I can think of is to format your email in a professional way and to inform users to add your email address to their address book.
    Researching email header might help as well, but I don't know much about it.

    Author Closing Comment

    After changing the body content and subject, adding a couple of email headers and adding a true "from" address we passed the spam filter

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now