我发送电子邮件时从右到左

时间:2015-03-29 22:30:36

标签: vb.net email

我有Windows应用程序向客户发送电子邮件,一切正常但电子邮件到达左侧的问题。我怎么能让它从左到右?

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim iphost As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
    Dim Emailmessage As New MailMessage()

    Emailmessage.From = New MailAddress("myemail@live.com")
    Emailmessage.To.Add("mailto@live.com")
    Emailmessage.Subject = "NOOR Phone - مشترك جديد"
    Emailmessage.Body = ("اسم المشترك :" & TextBox1.Text & vbNewLine & "تاريخ التسجيل :" & DateTimePicker1.Text & vbNewLine & "         الهاتف :        " & TextBox3.Text & vbNewLine & "الشركة : " & ComboBox1.Text & vbNewLine & "الدفع الشهري : " & TextBox4.Text & vbNewLine & "رقم الشريحة : " & TextBox5.Text & "")
    Dim smtp As New SmtpClient("smtp.live.com")
    smtp.Port = 587
    smtp.EnableSsl = True
    smtp.Credentials = New System.Net.NetworkCredential("myemail@live.com", "password")
    smtp.Send(Emailmessage)
End Sub

2 个答案:

答案 0 :(得分:1)

将邮件正文包裹在一个从右到左方向的div中:

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim iphost As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
    Dim Emailmessage As New MailMessage()

    Emailmessage.From = New MailAddress("myemail@live.com")
    Emailmessage.To.Add("mailto@live.com")
    Emailmessage.Subject = "NOOR Phone - مشترك جديد"
    Emailmessage.Body = ("<div style='direction:rtl'>اسم المشترك :" & TextBox1.Text & vbNewLine & "تاريخ التسجيل :" & DateTimePicker1.Text & vbNewLine & "         الهاتف :        " & TextBox3.Text & vbNewLine & "الشركة : " & ComboBox1.Text & vbNewLine & "الدفع الشهري : " & TextBox4.Text & vbNewLine & "رقم الشريحة : " & TextBox5.Text & "</div>")
    Dim smtp As New SmtpClient("smtp.live.com")
    smtp.Port = 587
    smtp.EnableSsl = True
    smtp.Credentials = New System.Net.NetworkCredential("myemail@live.com", "password")
    smtp.Send(Emailmessage)
End Sub

答案 1 :(得分:0)

这是一个古老的问题,但是自最近遇到这个问题后,我想给出自己的答案。 在以下段落中:

Emailmessage.Body = ("<div style='direction:rtl'>اسم المشترك :" & TextBox1.Text & vbNewLine & "تاريخ التسجيل :" & DateTimePicker1.Text & vbNewLine & "         الهاتف :        " & TextBox3.Text & vbNewLine & "الشركة : " & ComboBox1.Text & vbNewLine & "الدفع الشهري : " & TextBox4.Text & vbNewLine & "رقم الشريحة : " & TextBox5.Text & "</div>")

更改<div style='direction:rtl'> 到:<div dir=RTL>

它也可以用作:<p dir=RTL>

(别忘了在结尾处关闭段落)

以下是在我自己的项目中对我有用的解决方案:

MailMessage message = new MailMessage();                    
message.Subject = string.Format($"{model.MessageSubject}");                    
message.From = new MailAddress(model.MessageFrom);
message.To.Add(new MailAddress(model.MessageTo));
message.Body = string.Format($"<p dir=RTL>{model.MessageBody}</p>");
message.IsBodyHtml = true;

如果您将伪造的邮件发送到自己的地址并使用Microsoft Outlook打开,则该邮件将按从右到左的顺序显示。希望这对某人有帮助。