SMTPClient email sometimes going to Junk Mail - asp.net

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!

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.

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.

Based on your comments:
The email is coming from your website's SMTP using your domain.
The email is being received by your Exchange server which also uses the same domain.
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 joe#yourcompany.com sending an email to bob#yourcompany.com. 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)

Related

How to prevent outlook.office.com from displaying message source in emails

Our club directors are using online.outlook.com as a webmail solution for messaging, and I have noticed something peculiar in that while messages sent to the directors from a mail client like Thunderbird look ok, any emails sent from our online webform look a mess.
For example...
Contact = 192.168.0.2 via /contact.asp?
ID=7&Subject=Text+format&Name=John&Email=john%40example.com&Message=Click+inside+calendar+to+add+event%2C+move+or+resize+existing+events%2C+select+multiple+days%2C+etc.&g-recaptcha-response=03AGdBq26BbA8M9TkyW521mNLZ6nksqV4EdzajclTJ653GsN4E3opCUKEdrt5hA1orva_V3OF7TghktsatMauhu1Oue6TzMF2xO1wPssI7PCOiwMKcdVGWEprbRkaBxKhyJWo52vFNiuN3cO8xobvydyNcbKyYqPNWn0dZVwhN2Tav4WRQWOp5x1-0lANfpVBtVz8RaxoeAMii5e97tgCbGb06y0VjusA6zYappXDl__E95Zm5Lxm7TakVGhWx-SzRpFsmJJB3aCP1TvsEJIDMn3NN31OZA2SpsvblGywTdAUYQoy7VaWghjgcOoOdCZ2y-oE06l2p5OZ5q1Et_w4SClcrouAjL4rge-i8EIucpYJHKJZtPPoDTT9HPlc4h0T0Hab8frxxeB280O22kPicnYo7lAkU_3TCoj39eYEfyv1s40F5m9opfVF5p36mMRRVcpasp6EXjlwVf8FM6fAgqaMYGd6S6_u1vw&Submit=Submit
-------------------------------------------------------------
Name: John
Email: john#example.com
Subject: Text format
-------------------------------------------------------------
Dear John
Click inside calendar to add event, move or resize existing events, select multiple days, etc.
Everything above "Name: John" should not be shown and is not shown when the email is sent from Thunderbird.
The code that I used on the mail page looks like...
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... /sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... smtpserver") = strMailServer
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... thenticate") = strSmtpAuthenticate
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... ndusername") = strSmptAuthUser
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... ndpassword") = strSmptAuthPass
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... serverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/config ... iontimeout") = 60
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = strName & " <" & strEmail & ">"
ObjSendMail.Subject = strSubject
ObjSendMail.From = strFromName & " <" & strFromEmail & ">"
ObjSendMail.ReplyTo = strSender & " <" & strSenderEmail & ">"
ObjSendMail.BodyPart.Charset = "UTF-8"
ObjSendMail.TextBody = strEmailBody
ObjSendMail.TextBodyPart.Charset = "UTF-8"
On Error Resume Next
ObjSendMail.Send
Set ObjSendMail = Nothing
Charset for the page is set to UTF-8.
Anyone seen this before and know how to prevent it?
I had a similar problem and spent days trying to solve it. In the end it was quite simple to fix but difficult to understand how it could be so. But I finally got to send emails that didn't include header data in the email body.
I found that all my pages were using the same include.asp that contained a collection of functions. I solved the problem when I disabled any that were using server variables such as...
strCheckIPnumber = Request.ServerVariables("REMOTE_ADDR")
I didn't want to lose those server variables, so I made their collection conditional so that the webforms for email could exclude them.

Cannot send email from godaddy smtp using classic asp - going mad

I am really struggling with something which is pretty basic and need some help as it was not forthcoming from godaddy support!
For some reason the code below is not sending out any emails.
Code seems to be executed property and riddled it with lots of debug msgs but to no helping!
Te "From" email address is valid and has no issues! Any ideas? Port?
cheers, Jay
<%
Dim objNewMail
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "info#example.com"
objNewMail.To = "info#example.com"
objNewMail.Subject = "Interesting property sent by xxx"
objNewMail.TextBody = "Click the following link to see the property :" '& vbcr & vbcr & "http://www.maltawide.eu/default.asp?pid="
' GoDaddy SMTP Settings
'I had to remove the smpt settings as I dont have enough rep to post two links!
Response.Write ("Message sent successfully!")
%>
I'm not sure why your message failed, but here is code from a working mail form hosted at GoDaddy. All you need to do is build the form page to submit the form fields used in the script, or change the form field names in the script to match your existing form, or replace the forms with strings. Examples of both form entry and assigned variable values are included in the example's ' Create the message part of the code.
<%
Dim strBody
Dim strToAddress
Dim strFromAddress
Dim strReplyAddress
Dim strBlindCC
' Create the message
strBody = Request.Form("Message")
strToAddress = Request.Form("ToAddress")
strFromAddress = Request.Form("FromAddress")
strReplyAddress = "NoReply#WebSite.com"
strBlindCC = "BlindCC#WebSite.com"
' Include the schemas
sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"
' Set the mail server configuration
Set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendUrl)=2 ' cdoSendUsingPort
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
objConfig.Fields.Update
' Send the message
Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration=objConfig
objMail.From=strFromAddress
objMail.ReplyTo=strReplyAddress
objMail.To=strToAddress
objMail.BCC=strBlindCC
objMail.Subject=strSubject
objMail.HTMLBody = strBody
objMail.Send
%>

Fail Sending Email Unable To Connect the Remote Server

im facing error when sending email. here is the error
what is the actual error for this exception because i newbie in in this, by the way here is my code line:
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("test#gmail.com", "passwordexample")
SmtpServer.EnableSsl = True
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("test#gmail.com")
mail.To.Add("examplemail#gmail.com")
mail.Subject = "Change Request Submitted"
mail.Body = "Dear User, " & Environment.NewLine & Environment.NewLine & Environment.NewLine & Environment.NewLine & "One Notification have been submitted," & Environment.NewLine & "Please check the change request on the intranet application"
//ad this line the error SmtpServer.Send(mail)
SmtpServer.EnableSsl = True
MsgBox("Notification emailed successfully")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Please see this answer...
Sending Email from Visual Basic
If you still can't send the email....
Have you enabled POP or IMAP in Gmail?
Sign in to the Gmail web interface.Open the 'Forwarding and POP/IMAP' tab on your 'Settings' page, and configure IMAP or POP. After enabling this in Gmail, make sure you click 'Save Changes' so Gmail can communicate with your mail client.
If you have 2 step verification..
Get an Application-Specific Password
Google will automatically generate a password that you will need only once, when you set up Google Mail on your mobile device or email software. You can easily generate a password for each device or email software you want to use.
Step 1:
At the bottom of the 2-step verification screen, next to Application-specific passwords, click Manage application-specific passwords. The Authorized Access to your Google Account screen will open.
Step 2:
On the Authorized Access to your Google Account screen, in the Name field, type in a name to help you remember what application you are using to access your account and click Generate password. You will then see a password which you will use to configure your mobile device or email software. Keep this screen open until you are ready to enter the password (see part 4, below). The password creation with the device name will show at the bottom. When you are done using the password, click Done.
Step 3:
To set up a password for another device or email software, simply type in the name of it in the Name field and click Generate password. You will receive another password.
See more here...
http://www.oit.umass.edu/support/google-apps/configure-google-mail-email-software-mobile-devices
Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New Net.NetworkCredential("EMAIL FROM#gmail.com", "YOUR PASSWORD")
SmtpServer.Port = 25
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
Dim omail As New MailMessage()
omail.From = New MailAddress("FROM EMAIL #gmail.com", "Message", System.Text.Encoding.UTF8)
omail.Subject = "test subject"
omail.To.Add("test#gmail.com")
SmtpServer.SendAsync(omail, Nothing)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
if that didn't work try
SmtpServer.Port = 587

ASP email script

I have a form that I validate that data with, and what I'm wondering is, do I need to sanitize the data JUST to send an email? The email will be sent to a predefined email address. Basically the form just ask for a name, email (of the person using the form), and a url.
Then this gets sent to the predefined email address. IS something like this safe enough to use? Is it vulnerable to use a simple ASP page like this:
<%
dim objMessage
dim FullName
FullName=Request.QueryString("name")
dim email
email=Request.QueryString("email")
dim videourl
videourl=Request.QueryString("video")
dim txtMessage
txtMessage="<b><br><br>Name: " & FullName & "<br>Email: " & email & "<br><br>Video URL: " & videourl
objMessage = CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Subject = "qContest Submission"
objMessage.From = email
objMessage.To = "predefined#email.org"
objMessage.HTMLBody = txtMessage
objMessage.Send
%>
NOTE: This is NOT using any database or anything like that...
Also this script is being called via AJAX, if that matters...
always use Server.HTMLEncode when showig user-posted data in HTML. In this case you put it in the HTMLBody of the email, so I would definitely HTMLEncode:
FullName = Server.HTMLEncode(Request.QueryString("name"))
etc. This avoids the possibility to post vulnerable things like Javascript as that could be executed when opening the email.

Display Message to user and then abandon Session

I have added Two Factor Authentication to my Mobile ASP.Net Web App. When the user successfully enters their User Name and Password then a pin number is emailed to their email address which is stored in the database. The issue I am having is that after notifying the user that they don't have an email defined and then reload the login page but my code isn't notifying the user rather it is just reloading the Login.aspx page:
Private Sub GeneratePin()
Dim r As New Random(System.DateTime.Now.Millisecond)
_Pin = CStr(r.Next(1000, 99999))
_email = CIAppGlobals.CurrentUser.UsrContactEmail
With lblPin
.Text = "PIN has been emailed to the you please check your email now."
End With
If Not String.IsNullOrEmpty(_email) Then
Dim Message As String = " Your Mobile PIN number is " & _Pin & vbNewLine & "From IP Address: " & CIAppGlobals.AppSettings.ClientIP
Tools.SendEmail(CIAppGlobals.CurrentUser.UsrContactEmail, "Mobile App - Two Factor Authentication", Message)
Else
Dim sText As String = "Please contact the Administrator You do not have an email address defined within Application."
'DirectCast(HttpContext.Current.Handler, System.Web.UI.Page).ClientScript.RegisterStartupScript(Me.[GetType](), "test", "alert('" & sText & "')", True)
Response.Write("<script>alert('" & sText & "');</script>")
Thread.Sleep(5000)
'Session.Abandon()
'FormsAuthentication.SignOut()
Response.Redirect(ParentFolder & "/Login.aspx")
End If
End Sub
Your call to Response.Redirect() is causing anything you output not to be displayed. You need to remove that, then output a link or some javascript to go to the login page.
Also: you need to remove the call to Thread.Sleep(). That is causing a needless delay and keeping an asp.net thread busy doing nothing. It's not doing what you think it is...

Resources