Reputation: 173
I have a working function for using sendgrid web api. The function worked without any issue but now i would like to add in the ability to have a "ReplyTo" email address. The working code is as follows:
Private Function CreateMailMessage(ByVal fromAddr As String, fromName As String, ByVal toAddr As String, ByVal ccAddr As String, ByVal bccAddr As String, ByVal subject As String, ByVal contents As String) As SendGrid.IMail
Dim returnVar As SendGrid.IMail = SendGrid.Mail.GetInstance
returnVar.From = New System.Net.Mail.MailAddress(fromAddr, fromName)
returnVar.Subject = subject
If contents.Contains("<html") Then
returnVar.Html = contents
Else
returnVar.Text = contents
End If
For Each aStr As String In toAddr.Split(CChar(";"))
returnVar.AddTo(aStr)
Next
If Not (String.IsNullOrWhiteSpace(ccAddr)) Then
For Each aStr As String In ccAddr.Split(CChar(";"))
'Sendgrid doesnt support CC via the webapi so we need to use Bcc
returnVar.AddBcc(aStr)
Next
End If
If Not (String.IsNullOrWhiteSpace(bccAddr)) Then
For Each aStr As String In bccAddr.Split(CChar(";"))
returnVar.AddBcc(aStr)
Next
End If
Return returnVar
End Function
and when adding the in the ReplyTo i tried the following:
Private Function CreateMailMessage(ByVal replytoAddr As String, ByVal fromAddr As String, fromName As String, ByVal toAddr As String, ByVal ccAddr As String, ByVal bccAddr As String, ByVal subject As String, ByVal contents As String) As SendGrid.IMail
Dim returnVar As SendGrid.IMail = SendGrid.Mail.GetInstance
If Not (String.IsNullOrWhiteSpace(replytoAddr)) Then
returnVar.ReplyToList.Add(New System.Net.Mail.MailAddress(replytoAddr))
End If
returnVar.From = New System.Net.Mail.MailAddress(fromAddr, fromName)
returnVar.Subject = subject
If contents.Contains("<html") Then
returnVar.Html = contents
Else
returnVar.Text = contents
End If
For Each aStr As String In toAddr.Split(CChar(";"))
returnVar.AddTo(aStr)
Next
If Not (String.IsNullOrWhiteSpace(ccAddr)) Then
For Each aStr As String In ccAddr.Split(CChar(";"))
'Sendgrid doesnt support CC via the webapi so we need to use Bcc
returnVar.AddBcc(aStr)
Next
End If
If Not (String.IsNullOrWhiteSpace(bccAddr)) Then
For Each aStr As String In bccAddr.Split(CChar(";"))
returnVar.AddBcc(aStr)
Next
End If
Return returnVar
End Function
it would seem Replytolist is not part of sendgrid? Anyone seen this?
Upvotes: 1
Views: 200
Reputation: 9814
I maintain the SendGrid library. Sorry, this is a known issue that I haven't gotten around to fixing yet. In the meantime you can use the obsolete ReplyTo
.
Upvotes: 1