2010-10-25 66 views
1

我用SmtpMail爲用戶轉發網站內容。用戶填寫包括名字和電子郵件的表格。SmtpMail - 更改「從地址」來命名

電子郵件發送具有完整的電子郵件地址作爲「發件人地址」,在收件人的收件箱(他們看到來自:[email protected]而我希望他們看到來自:喬)。

我如何格式化「從地址」是用戶輸入的名字?

謝謝!

回答

0

我結束了使用格式爲:mailer.From = name & "<" & emailer & ">"

這格式化的地址,包括姓名以及郵箱地址。它將在大多數電子郵件客戶端中顯示爲Joe <[email protected]>。這是我期望的結果。

謝謝Knslyr和lincolnk的支持。

2

MailAddress類有一個可選的參數,你可以指定顯示名稱。我認爲它會在現場使用。

Dim from As MailAddress = New MailAddress("[email protected]", "Ben Miller") 
Dim to As MailAddress = New MailAddress("[email protected]", "Jane Clayton") 
Dim message As MailMessage = New MailMessage(from, to) 
+0

這會導致網頁無法加載...任何想法? – Joe 2010-10-25 20:51:36

+0

@Joe ummmm ....不。也許發佈你有問題的代碼? – lincolnk 2010-10-25 20:54:48

+0

下面是傳遞主要郵件變量的代碼部分。 「接收者,電子郵件,nombre」是從表單中提取的3個變量。我需要「nombre」通過mailer.from字段而不是emailer。 mailer.To = receiver mailer.Bcc = "[email protected]" mailer.From = emailer mailer.BodyFormat = MailFormat.Html mailer.Subject = "Subject Line Here" Joe 2010-10-25 21:31:46

2

這一直爲我工作:

Dim myMessage As New MailMessage 

    Dim myFrom As MailAddress = New MailAddress("[email protected]", "Bob Denver") 
    Dim myTo As MailAddress = New MailAddress("[email protected]", "Steve Miller") 

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

這種方法顯示「拉梅斯」而不是「[email protected]

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"" <[email protected]>" 

    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