user3033348
user3033348

Reputation: 143

SMTPClient email sometimes going to Junk Mail

I'm having a difficult time understanding why email I send from my website by using SMTP is going to Outlook's junk mail. Here is my code:

       Dim windowsLoginName As System.String = HttpContext.Current.User.Identity.Name

    Dim split As String() = Nothing
    Dim vname As String

    'Get network login name (name only)
    split = windowsLoginName.Split("\".ToCharArray)
    vname = split(1)

'create the mail message
    Dim mail As New MailMessage()

    'set the addresses
    mail.From = New MailAddress(vname & "@x.com")
    mail.To.Add(txtWhoApproves.Text)

    'set the content
    Dim varstreason, vartxt, vartxt2, varbody As String
    varstreason = DropDownList1.SelectedItem.Text

    If TextBox1.Text = TextBox2.Text Then

        If CheckBox1.Checked = True Then
            varbody = TextBox3.Text & " has requested the following time off:  " & System.Environment.NewLine & varstreason & " - " & TextBox1.Text & " - All Day"
        Else
            vartxt = varstreason & " - " & TextBox1.Text
            vartxt2 = DropDownList2.SelectedValue & " to " & DropDownList3.SelectedValue
            varbody = TextBox3.Text & " has requested the following time off:  " & vartxt & " - " & vartxt2
        End If

    Else
        varbody = TextBox3.Text & " has requested the following time off:  " & varstreason & " - " & TextBox1.Text & " to " & TextBox2.Text
    End If

    mail.Subject = "Time Off Approval Requested"
    mail.Body = varbody

    'send the message
    Dim smtp As New SmtpClient("(IP Address of email server)")

    'to authenticate we set the username and password properites on the SmtpClient
    'smtp.Credentials = New NetworkCredential("username", "secret")
    smtp.Send(mail)

I have the email coming from whoever is logged onto the network. Since it's multiple people, I remarked out smtp.Credentials because the password is different for each user (and changes periodically). I'm thinking that this is somehow causing the email to sometimes go into the junk email.

And ideas? How can I prevent these emails from going into junk? We are using an Exchange 2010 server, and Outlook 2007, 2010, or 2013. Thanks in advance!

Upvotes: 1

Views: 1377

Answers (3)

Gortonington
Gortonington

Reputation: 3587

Based on your comments:

  1. The email is coming from your website's SMTP using your domain.
  2. The email is being received by your Exchange server which also uses the same domain.
  3. The emails are only for an internal audience.

From here I would recommend 2 different solutions:

First Solution:

Instead of using your website's SMTP, instead use your Exchange server to send the email. This will work the same as [email protected] sending an email to [email protected]. The email will never need to leave the server or hit any filters(unless you set up internal filters), so it will not hit the spam box (unless an end user specifically sets it up this way). Check out this site for some help in how to accomplish this: https://www.emailarchitect.net/easendmail/kb/vbnet.aspx

Second Solution:

Use group policies to add the email address to safe senders list for all your users.(https://social.technet.microsoft.com/Forums/office/en-US/c0714d7d-2a42-4b0f-9f1d-63234c7278a0/appending-outlook-safe-senders-list-via-gpo) This seems like it should be an easy solution, but the issue is that it still may not work since you have 2 different servers using the same domain. So although the address may be added in, Outlook may view it as being a different address since it is not coming from the Exchange server. The other option in this solution is to have everyone that gets your email to add it to safe senders directly from the email they receive. That would do it, but hugely inefficient and manual.

For some more in-depth info into the processes and technology behind email, I would recommend checking out the "How Email Works" series of articles by Click-Z (part 1 - https://www.clickz.com/clickz/column/2411041/how-email-works-part-one-the-story-of-send)

Upvotes: 1

ljlozano
ljlozano

Reputation: 191

Spam filtering for email is based on the content of the subject, message, and attachments. It also filters based on things such as what host/IP you're sending from. If you attempt to send an email via SMTP using a host such as gmail, you'll likely notice it will inbox.

Upvotes: 1

user4416781
user4416781

Reputation:

May be your website is listed as spamming in outlook security systems, or your email contain some spam words or links that causes emails to go in junk or spam box.

Upvotes: 2

Related Questions