How to control tracking options and tags when using Mailgun's SMTP option (i.e. not using their API) - tags

I’m using python to send emails using Mailgun’s SMTP server. I wish to use Mailgun’s builtin ability to tag my messages, and to track open and click events.
I know this can be done using Mailgun’s send message API, by adding headers like o:tag, o:tracking, o:tracking-clicks and o:tracking-opens (as explained here: https://documentation.mailgun.com/en/latest/api-sending.html#sending)
However, seeing as I'm the SMTP gateway and not the API, I’m trying to understand how to achieve the same result - emails that are tagged and fully tracked in Mailgun.
Any thoughts on how it can be done?
This is my little script at the moment:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()

Found it!
The following X-Mailgun headers can be added:
https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-smtp
So my script would be:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
message["X-Mailgun-Tag"] = "<tag>"
message["X-Mailgun-Track"] = "yes"
message["X-Mailgun-Track-Clicks"] = "yes"
message["X-Mailgun-Track-Opens"] = "yes"
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Now my email is tagged (can be analysed on a tag level in Mailgun), and clicks are tracked.
Happy days!

Related

Sending email with Classic ASP through Godaddy

I'm trying to send email using Classic ASP from my website at Godaddy. Unfortunately, the cod I have from 10-15 years ago doesn't work (imagine that! lol). Here's the code. Can someone tell me what has changed since then? desperately await your reply. Thank you!
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = false
.Item(cdoSendUserName) = "email#mywebsite.com"
.Item(cdoSendPassword) = "MyPassword"
.Item(cdoURLProxyServer) = "server:25"
'.Item(cdoSendUsingMethod) = cdoSendUsingPickup
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "relay-hosting.secureserver.net"
.Item(cdoURLGetLatestVersion) = True
.Update
End With
'Create mail object
Set cdoMessage = CreateObject("CDO.Message")
'Apply the settings to the message object then send the email
With cdoMessage
Set .Configuration = cdoConfig
.From = "Support (email#mywebsite)"
.To = "The User (user#email.com)"
.BCC = ""
.Subject = "This is a test email."
.TextBody = "This is a test email. If it were a real email there would be some blah blah blah here! This concludes the test of the Godaddy email message."
.Send
End With
'Cleanup mail objects
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Ok folks. This is for the people that need a guiding hand from time to time. However, make sure you enter the right username and password. When hosting on Godaddy you could have up to three different usernames and passwords. You have your Godaddy account username and password (that's not it!), you have a username and password for Plesk (that's not it either!). Then you have a username and password for your primary website (that's the one you want!). Even though you might have several different websites under your hosting, only one will be the primary. Mine was for the email and password that are associated with that prime website. Once you get this code posted you should be good to go. However, you might have to wait a while in order for it to start working. For me it took about 8 hours for the DNS to catch hold of what I was doing and start sending my emails through. Once it did though, now it works great! Enjoy!
Dim objNewMail
'Your email information
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "your-email#this-website.com"
objNewMail.Cc = "your-email#this-website.com"
objNewMail.To = "send-to#their-email.com"
objNewMail.Subject = "This is a test email"
objNewMail.TextBody = "this is a test email"
' GoDaddy SMTP Settings
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="relay-hosting.secureserver.net"
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendUserName") = "your-primary-website-username"
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendPassword") = "your-primary-website-password"
objNewMail.Configuration.Fields.Update
objNewMail.Send
'After the Send method, NewMail Object become Invalid
Set objNewMail = Nothing

Classic ASP - Implementing SMTP authentication in sending emails via CDONTS

Below is an already working code in classic ASP to send an email. Can we implement SMTP authentication to this code?
I have implemented using CDO, but would like to know if we can implement SMTP authentication for CDONTS. Please see my code below:
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.to = "testrecipient#domain.com"
objCDO.From = "testsender#domain.com" 'CustEmail
objCDO.Subject = "Test Subject"
objCDO.BodyFormat = 0
objCDO.MailFormat = 0
objCDO.Body = "This is a test message"
objCDO.Importance = 0 'High importance!
objCDO.Send 'Send off the email!
'Cleanup
Set objCDO = Nothing
ReplySent="Email sent!"
Response.write(ReplySent)
Response.End

Cannot send mail using smtp.gmail.com from ONLY one specific Google account

I am not able to send mail via smtp.gmail.com for ONLY one specific Google account. When I use another Google account my VBS script sends mail successfully so I know the script is working correctly.
Both accounts have the Less Secure Apps turned ON.
I have also tried the Display Unlock Captcha multiple times.
POP and IMAP has been enabled for both accounts.
It looks like there is an issue with that particular account and I have already posted a request for support in the Gmail help forums.
https://productforums.google.com/forum/#!topic/gmail/8XFKONFbDA8
My VBS Script:
Dim emailObj
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "******#gmail.com"
emailObj.To = "******#gmail.com"
emailObj.Subject = "Test Email"
emailObj.TextBody = "Testing Email Functionality"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
'First Account
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "******#gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "************"
'Second Account
'emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "******#gmail.com"
'emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "************"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 Then
Msgbox "Done"
Else
Msgbox err
End If
Account 1 Test (Not Working)
Account 2 Test (Working)
Error Message: The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
Any help would be appreciated.
I had a same error. There is an option in Google account - https://myaccount.google.com/lesssecureapps. I turned it On and it helped me.

GitLab "Reply-To" feature using Omnibus not working?

We currently are running the latest version of GitLab (v8.0.1) which is installed using the Omnibus package and trying to enable the new "reply-to" feature but nothing is happening.
We followed these instructions:
http://doc.gitlab.com/ce/incoming_email/README.html (specifically the Gmail instructions). We configured a new Gmail account with lesser-security and we also use the SMTP configuration.
The email, when replied to, is being sent to the GMail account but from there nothing is happening. The doco seems a little sparse but is GitLab supposed to pick that email up (via IMAP) and update the issue? If so, nothing is happening.
Our settings in the /etc/gitlab/gitlab.rb (and I had to add the "incoming-mail" section manually because it was not there) looks like this:
# SMTP setup
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "aws"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "AWSUSER"
gitlab_rails['smtp_password'] = "AWSPASS"
gitlab_rails['smtp_domain'] = "git.ourdomain.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
# gitlab_rails['smtp_tls'] = false
# gitlab_rails['smtp_openssl_verify_mode'] = 'none' # Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert', see http://api.rubyonrails.org/classes/ActionMailer/Base.html
# gitlab_rails['smtp_ca_path'] = "/etc/ssl/certs"
# gitlab_rails['smtp_ca_file'] = "/etc/ssl/certs/ca-certificates.crt"
# Configuration for Gmail / Google Apps, assumes mailbox gitlab-incoming#gmail.com
gitlab_rails['incoming_email_enabled'] = true
gitlab_rails['incoming_email_address'] = "gitlab+%{key}#ourdomain.com"
gitlab_rails['incoming_email_email'] = "gitlab#ourdomain.com"
gitlab_rails['incoming_email_password'] = "GLPASS"
gitlab_rails['incoming_email_host'] = "imap.gmail.com"
gitlab_rails['incoming_email_port'] = 993
gitlab_rails['incoming_email_ssl'] = true
gitlab_rails['incoming_email_start_tls'] = false
gitlab_rails['incoming_email_mailbox_name'] = "inbox"
For me installing the last update and restarting the server seemed to solve the problem (I did restart the server the first time as well but it still was not working).

Serilog Email sink

I'm trying to send emails using Serilog.Sinks.Email NuGet package (v1.5.0.0) with the Mandrill SMTP service. The following code executes but does not send any emails. When I try and use the same credentials using the System.Net.Mail.SmtpClient, it works and send an email.
EmailConnectionInfo info = new EmailConnectionInfo()
{
EmailSubject = "Email subject",
FromEmail = "from#gmail.com",
MailServer = "smtp.mandrillapp.com",
NetworkCredentials = new NetworkCredential("mandrill_username", "mandrill_apikey"),
Port = 587,
ToEmail = "to#gmail.com"
};
Log.Logger = new LoggerConfiguration()
.WriteTo.Email(info)
.CreateLogger();
Log.Error("Houston we have a problem");
As you spotted, this was a bug in the latest build of the Email sink, which your graciously-provided pull request has fixed. Version 1.5.13 of the sink, now on NuGet, includes the fix.