【问题标题】:SmtpMail - Change the "From Address" to NameSmtpMail - 将“发件人地址”更改为名称
【发布时间】:2011-04-30 10:13:06
【问题描述】:

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

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

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

谢谢!

【问题讨论】:

    标签: vb.net email smtp


    【解决方案1】:

    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)
    

    【讨论】:

    • 这导致页面无法加载...有什么想法吗?
    • 下面是传递主要邮件变量的代码部分。 “receiver, emailer, nombre”是从表单中提取的 3 个变量。我需要通过 mailer.from 字段而不是 emailer 传递“名词”。 mailer.To = 收件人 mailer.Bcc = "Bcc@test.com" mailer.From = emailer mailer.BodyFormat = MailFormat.Html mailer.Subject = "Subject Line Here"
    【解决方案2】:

    这一直对我有用:

        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)
    

    【讨论】:

      【解决方案3】:

      我最终使用的格式是:mailer.From = name & "<" & emailer & ">"

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

      感谢 Knslyr 和 lincolnk 的支持。

      【讨论】:

        【解决方案4】:

        此方法显示“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
        

        【讨论】:

          猜你喜欢
          • 2015-02-16
          • 2017-09-23
          • 1970-01-01
          • 2011-02-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-08
          • 1970-01-01
          相关资源
          最近更新 更多