English 中文(简体)
SmtpMail-将“发件人地址”更改为“姓名”
原标题:SmtpMail - Change the "From Address" to Name

我使用SmtpMail为用户转发网站内容。用户填写一个包含名字和电子邮件的表格。

发送的电子邮件的完整电子邮件地址为收件人收件箱中的“发件人地址”(他们看到发件人:Joe@Gmail.com而我想让他们看到From:Joe)。

如何将“发件人地址”格式化为用户输入的名字?

谢谢

最佳回答

我最终使用的格式是:mailer.From=name&;“<;”&;电子邮件发件人&;“>;”

这将格式化发件人地址以包括姓名和电子邮件地址。它将在大多数电子邮件客户端中显示为Joe<;Joe@email.com>。这是我想要的结果。

感谢Knslyr和lincolnk的支持。

问题回答

MailAddress类有一个可选参数,您可以在其中指定显示名称。我认为它将在存在时使用。

Dim from As MailAddress = New MailAddress("ben@contoso.com", "Ben Miller")
Dim to As MailAddress = New MailAddress("jane@contoso.com", "Jane Clayton")
Dim message As MailMessage = New MailMessage(from, to)

这一直对我有效:

    Dim myMessage As New MailMessage

    Dim myFrom As MailAddress = New MailAddress("bob@contoso.com", "Bob Denver")
    Dim myTo As MailAddress = New MailAddress("steve@contoso.com", "Steve Miller")

    myMessage.From = myFrom
    myMessage.To.Add(myTo)

该方法显示Rameez而不是Rameez@abc.com.pk

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim objRecip As Recipient
    Dim strMsg As String
    Dim res As Integer
    Dim strBcc As String
    On Error Resume Next

    strBcc = """Rameez"" <Rameez@abc.com.pk>"

    Set objRecip = Item.Recipients.Add(strBcc)
    objRecip.Type = olBCC
        If Not objRecip.Resolve Then
            strMsg = "Could not resolve the Bcc recipient. " & _
            "Do you want still to send the message?"
            res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
            "Could Not Resolve Bcc Recipient")
            If res = vbNo Then
                Cancel = True
            End If
        End If
    Set objRecip = Nothing

    End Sub




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?