Hi im trying to send a notification email when event took a place, but the problem is the email marked as spam and listed in junk mail, How can avoid junk mail and send email direct to inbox 🙂
Here is my code:
Function SendResignEmail(PF As String, User As String, First_Name As String, Last_Name As String, Unit As String, EndDate As Date, Reason As String, JMTS As String, EmailTo() As String, EmailCC() As String, EmailSub As String)
Dim EmailBody As String = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta content='en-us' http-equiv='Content-Language' /><meta content='text/html; charset=utf-8' http-equiv='Content-Type' /><title>Untitled 1</title><style type='text/css'> p.MsoNormal {margin-bottom:.0001pt; font-size:11.0pt; font-family:'Calibri','sans-serif'; margin-left: 0in; margin-right: 0in; margin-top: 0in;} table.MsoNormalTable {font-size:10.0pt; font-family:'Times New Roman','serif';}a:link {color:blue; text-decoration:underline; text-underline:single;}.auto-style1 { font-family: Arial, sans-serif; font-size: 10pt; color: #9B5F9B;}</style></head><body><p class='MsoNormal'><span style='color:black'>Dear team,</span></p><p class='MsoNormal'><span style='color:black'><o:p> </o:p></span></p><p class='MsoNormal'><span style='color:black'><o:p> </o:p></span></p><p class='MsoNormal'><span style='color:black'>Kindly be informed that the below agent had resigned and his last working day is " & EndDate.ToShortDateString & " </span><b><span style='font-size:12.0pt;color:black'>.</span></b><span style='color:black'><o:p></o:p></span></p><p class='MsoNormal'><span style='color:black'><o:p> </o:p></span></p><table border='0' cellpadding='0' cellspacing='0' class='MsoNormalTable' style='width:491.55pt;margin-left:-1.15pt;border-collapse:collapse;mso-yfti-tbllook: 1184;mso-padding-alt:0in 0in 0in 0in' width='655'> <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:15.75pt'> <td nowrap style='width: 48.0pt; border: solid windowtext 1.0pt; border-bottom: none; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='64'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>User<o:p></o:p></span></p> </td> <td nowrap style='width: 48.0pt; border-top: solid windowtext 1.0pt; border-left: none; border-bottom: none; border-right: solid windowtext 1.0pt; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='64'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>PF<o:p></o:p></span></p> </td> <td nowrap style='width: 138.75pt; border-top: solid windowtext 1.0pt; border-left: none; border-bottom: none; border-right: solid windowtext 1.0pt; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='185'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>Name<o:p></o:p></span></p> </td> <td nowrap style='width: 85.5pt; border-top: solid windowtext 1.0pt; border-left: none; border-bottom: none; border-right: solid windowtext 1.0pt; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='114'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>Area<o:p></o:p></span></p> </td> <td nowrap style='width: 43.05pt; border-top: solid windowtext 1.0pt; border-left: none; border-bottom: none; border-right: solid windowtext 1.0pt; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='57'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>End Date<o:p></o:p></span></p> </td> <td nowrap style='width: 70.2pt; border-top: solid windowtext 1.0pt; border-left: none; border-bottom: none; border-right: solid windowtext 1.0pt; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='94'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>Reason<o:p></o:p></span></p> </td> <td style='width: 58.05pt; border-top: solid windowtext 1.0pt; border-left: none; border-bottom: none; border-right: solid windowtext 1.0pt; background: #CCC0DA; padding: 0in 5.4pt 0in 5.4pt; height: 15.75pt' width='77'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>Mob #<o:p></o:p></span></p> </td> </tr> <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes;height:15.75pt'> <td nowrap style='width:48.0pt;border:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='64'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'> 6303<o:p></o:p></span></p> </td> <td nowrap style='width:48.0pt;border:solid windowtext 1.0pt; border-left:none;padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='64'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'> " & PF & "<o:p></o:p></span></p> </td> <td nowrap style='width:138.75pt;border:solid windowtext 1.0pt; border-left:none;padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='185'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>" & First_Name & " " & Last_Name & "</span><span style='font-size:9.0pt; font-family:"Tahoma","sans-serif";color:black'><o:p></o:p></span></p> </td> <td nowrap style='width:85.5pt;border:solid windowtext 1.0pt; border-left:none;padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='114'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>" & Unit & "<o:p></o:p></span></p> </td> <td nowrap style='width:43.05pt;border:solid windowtext 1.0pt; border-left:none;padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='57'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>" & EndDate.Day & "/" & EndDate.Month & "/" & EndDate.Year & "<o:p></o:p></span></p> </td> <td nowrap style='width:70.2pt;border:solid windowtext 1.0pt; border-left:none;padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='94'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>" & Reason & "<o:p></o:p></span></p> </td> <td style='width:58.05pt;border:solid windowtext 1.0pt;border-left: none;padding:0in 5.4pt 0in 5.4pt;height:15.75pt' width='77'> <p align='center' class='MsoNormal' style='text-align:center'> <span style='color:black'>" & JMTS & "<o:p></o:p></span></p> </td> </tr></table><p class='MsoNormal'><span style='color:black'><o:p> </o:p></span></p><p class='MsoNormal'><span style='color:#1F497D'><o:p> </o:p></span></p><p class='MsoNormal'><span style='color:black'>For your kind action if any .<o:p></o:p></span></p><p class='MsoNormal'><span style='color:#1F497D'><o:p> </o:p></span></p><p class='MsoNormal'><span style='color:#1F497D'><o:p> </o:p></span></p><p class='MsoNormal'>Thanks!</p><p class='MsoNormal'> </p><p class='MsoNormal'><o:p> </o:p></p><p class='MsoNormal'><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";color:black'><img height='80' src=cid:companylogo width='52' /><!--[if gte vml 1]><v:shapetype id='_x0000_t75' coordsize='21600,21600' o:spt='75' o:preferrelative='t' path='m@4@5l@4@11@9@11@9@5xe' filled='f' stroked='f'><v:stroke joinstyle='miter' xmlns:v='urn:schemas-microsoft-com:vml'/><v:formulas><v:f eqn='if lineDrawn pixelLineWidth 0' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='sum @0 1 0' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='sum 0 0 @1' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='prod @2 1 2' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='prod @3 21600 pixelWidth' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='prod @3 21600 pixelHeight' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='sum @0 0 1' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='prod @6 1 2' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='prod @7 21600 pixelWidth' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='sum @8 21600 0' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='prod @7 21600 pixelHeight' xmlns:v='urn:schemas-microsoft-com:vml'/><v:f eqn='sum @10 21600 0' xmlns:v='urn:schemas-microsoft-com:vml'/></v:formulas><v:path o:extrusionok='f' gradientshapeok='t' o:connecttype='rect' xmlnsv='urn:schemas-microsoft-com:vml'/><o:lock v:ext='edit' aspectratio='t' xmlns:o='urn:schemas-microsoft-com:office:office'/></v:shapetype><![endif]--><![if !vml]><![endif]><br /> </span><span style='font-size:12.0pt;font-family:"Arial","sans-serif";color:#9B5F9B'><br />Contact Center Notifications on behalf of " & Name & "</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'> </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p><p class='MsoNormal' style='margin-bottom:12.0pt'><span class='auto-style1'>Headcount</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#9B5F9B'><br /><br />Zain Jordan <br />PO Box 940821, Amman 11194, Jordan</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p><p class='MsoNormal' style='margin-bottom:12.0pt'></p></body></html>"
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("CCNotifications@xxxxx.com", "xxxxxx")
SmtpServer.Port = 25
SmtpServer.Host = "192.168.10.232"
mail = New MailMessage()
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(EmailBody, "@<(.|\n)*?>", String.Empty), Nothing, "text/plain")
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(EmailBody, Nothing, "text/html")
'create the LinkedResource (embedded image)
Dim logo As New LinkedResource("\\fastdell\users\sales\users\lo'ais\Head_Count\IMG\Zain_logo.jpg")
logo.ContentId = "companylogo"
'add the LinkedResource to the appropriate view
htmlView.LinkedResources.Add(logo)
plainView.LinkedResources.Add(logo)
mail.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8")
'add the views
mail.AlternateViews.Add(htmlView)
mail.AlternateViews.Add(plainView)
mail.From = New MailAddress("CCNotifications@xxxx.com", "CC Notifications")
For i As Integer = 0 To EmailTo.Length - 1
mail.To.Add(EmailTo(i))
Next
For i As Integer = 0 To EmailCC.Length - 1
mail.CC.Add(EmailCC(i))
Next
'mail.Bcc.Add("wall.of.ey3s@gmail.com")
mail.Subject = EmailSub
mail.IsBodyHtml = True
'mail.Body = EmailBody
SmtpServer.Send(mail)
'MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return Nothing
End Function
Thanks!
The code that sends the mail has no influence on whether the receiving mail server interprets your mail as spam. Just think about it. That would render all anti-spam measures useless, because spammers would simply us that functionality, too.
The only thing you can do is to add the senders mail address to the list of known addresses. But that has to be done on the receiving server’s side – again, nothing your program can control.