如何通过WPF应用程序发送电子邮件并标记为UnJunk

时间:2013-02-04 14:02:34

标签: wpf vb.net email send

嗨我试图在事件发生时发送通知电子邮件,但问题是标记为垃圾邮件并在垃圾邮件中列出的电子邮件,如何避免垃圾邮件并将电子邮件直接发送到收件箱:)

这是我的代码:

    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>&nbsp;</o:p></span></p><p class='MsoNormal'><span style='color:black'><o:p>&nbsp;</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>&nbsp;</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:&quot;Tahoma&quot;,&quot;sans-serif&quot;;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:&quot;Tahoma&quot;,&quot;sans-serif&quot;;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:&quot;Tahoma&quot;,&quot;sans-serif&quot;;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>&nbsp;</o:p></span></p><p class='MsoNormal'><span style='color:#1F497D'><o:p>&nbsp;</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>&nbsp;</o:p></span></p><p class='MsoNormal'><span style='color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class='MsoNormal'>Thanks!</p><p class='MsoNormal'>&nbsp;</p><p class='MsoNormal'><o:p>&nbsp;</o:p></p><p class='MsoNormal'><span style='font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;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 />&nbsp;</span><span style='font-size:12.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#9B5F9B'><br />Contact Center Notifications on behalf of " & Name & "</span><span style='font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black'> </span><span style='font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;'><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:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#9B5F9B'><br /><br />Zain Jordan <br />PO Box 940821, Amman 11194, Jordan</span><span style='font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;'><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

谢谢!

1 个答案:

答案 0 :(得分:0)

发送邮件的代码不会影响接收邮件服务器是否将您的邮件解释为垃圾邮件。考虑一下。这会使所有反垃圾邮件措施变得毫无用处,因为垃圾邮件发送者也只是我们的功能。

您唯一能做的就是将发件人邮件地址添加到已知地址列表中。但这必须在接收服务器端完成 - 再次,你的程序无法控制。